move sercom_reset() etc. out of busio/SPI.c to busio/__init__.c
This commit is contained in:
parent
79ee78e690
commit
fc440e7609
@ -36,7 +36,7 @@
|
|||||||
#include "shared-bindings/microcontroller/__init__.h"
|
#include "shared-bindings/microcontroller/__init__.h"
|
||||||
#include "supervisor/shared/translate.h"
|
#include "supervisor/shared/translate.h"
|
||||||
|
|
||||||
#include "common-hal/busio/SPI.h" // for never_reset_sercom
|
#include "common-hal/busio/__init__.h"
|
||||||
|
|
||||||
// Number of times to try to send packet if failed.
|
// Number of times to try to send packet if failed.
|
||||||
#define ATTEMPTS 2
|
#define ATTEMPTS 2
|
||||||
|
@ -32,7 +32,9 @@
|
|||||||
#include "peripheral_clk_config.h"
|
#include "peripheral_clk_config.h"
|
||||||
|
|
||||||
#include "supervisor/board.h"
|
#include "supervisor/board.h"
|
||||||
|
#include "common-hal/busio/__init__.h"
|
||||||
#include "common-hal/microcontroller/Pin.h"
|
#include "common-hal/microcontroller/Pin.h"
|
||||||
|
|
||||||
#include "hal/include/hal_gpio.h"
|
#include "hal/include/hal_gpio.h"
|
||||||
#include "hal/include/hal_spi_m_sync.h"
|
#include "hal/include/hal_spi_m_sync.h"
|
||||||
#include "hal/include/hpl_spi_m_sync.h"
|
#include "hal/include/hpl_spi_m_sync.h"
|
||||||
@ -40,43 +42,6 @@
|
|||||||
#include "samd/dma.h"
|
#include "samd/dma.h"
|
||||||
#include "samd/sercom.h"
|
#include "samd/sercom.h"
|
||||||
|
|
||||||
bool never_reset_sercoms[SERCOM_INST_NUM];
|
|
||||||
|
|
||||||
void never_reset_sercom(Sercom *sercom) {
|
|
||||||
// Reset all SERCOMs except the ones being used by on-board devices.
|
|
||||||
Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS;
|
|
||||||
for (int i = 0; i < SERCOM_INST_NUM; i++) {
|
|
||||||
if (sercom_instances[i] == sercom) {
|
|
||||||
never_reset_sercoms[i] = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void allow_reset_sercom(Sercom *sercom) {
|
|
||||||
// Reset all SERCOMs except the ones being used by on-board devices.
|
|
||||||
Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS;
|
|
||||||
for (int i = 0; i < SERCOM_INST_NUM; i++) {
|
|
||||||
if (sercom_instances[i] == sercom) {
|
|
||||||
never_reset_sercoms[i] = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void reset_sercoms(void) {
|
|
||||||
// Reset all SERCOMs except the ones being used by on-board devices.
|
|
||||||
Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS;
|
|
||||||
for (int i = 0; i < SERCOM_INST_NUM; i++) {
|
|
||||||
if (never_reset_sercoms[i]) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// SWRST is same for all modes of SERCOMs.
|
|
||||||
sercom_instances[i]->SPI.CTRLA.bit.SWRST = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
||||||
const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi,
|
const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi,
|
||||||
const mcu_pin_obj_t *miso) {
|
const mcu_pin_obj_t *miso) {
|
||||||
|
@ -42,8 +42,4 @@ typedef struct {
|
|||||||
uint8_t MISO_pin;
|
uint8_t MISO_pin;
|
||||||
} busio_spi_obj_t;
|
} busio_spi_obj_t;
|
||||||
|
|
||||||
void reset_sercoms(void);
|
|
||||||
void never_reset_sercom(Sercom *sercom);
|
|
||||||
|
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H
|
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
|
|
||||||
#include "samd/sercom.h"
|
#include "samd/sercom.h"
|
||||||
|
|
||||||
#include "common-hal/busio/SPI.h" // for never_reset_sercom
|
#include "common-hal/busio/__init__.h"
|
||||||
|
|
||||||
#define UART_DEBUG(...) (void)0
|
#define UART_DEBUG(...) (void)0
|
||||||
// #define UART_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__)
|
// #define UART_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__)
|
||||||
|
@ -1 +1,63 @@
|
|||||||
// No busio module functions.
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016 Scott Shawcroft
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "samd/sercom.h"
|
||||||
|
|
||||||
|
static bool never_reset_sercoms[SERCOM_INST_NUM];
|
||||||
|
|
||||||
|
void never_reset_sercom(Sercom *sercom) {
|
||||||
|
// Reset all SERCOMs except the ones being used by on-board devices.
|
||||||
|
Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS;
|
||||||
|
for (int i = 0; i < SERCOM_INST_NUM; i++) {
|
||||||
|
if (sercom_instances[i] == sercom) {
|
||||||
|
never_reset_sercoms[i] = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void allow_reset_sercom(Sercom *sercom) {
|
||||||
|
// Reset all SERCOMs except the ones being used by on-board devices.
|
||||||
|
Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS;
|
||||||
|
for (int i = 0; i < SERCOM_INST_NUM; i++) {
|
||||||
|
if (sercom_instances[i] == sercom) {
|
||||||
|
never_reset_sercoms[i] = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset_sercoms(void) {
|
||||||
|
// Reset all SERCOMs except the ones being used by on-board devices.
|
||||||
|
Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS;
|
||||||
|
for (int i = 0; i < SERCOM_INST_NUM; i++) {
|
||||||
|
if (never_reset_sercoms[i]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// SWRST is same for all modes of SERCOMs.
|
||||||
|
sercom_instances[i]->SPI.CTRLA.bit.SWRST = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
35
ports/atmel-samd/common-hal/busio/__init__.h
Normal file
35
ports/atmel-samd/common-hal/busio/__init__.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2016 Scott Shawcroft
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_INIT_H
|
||||||
|
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_INIT_H
|
||||||
|
|
||||||
|
void reset_sercoms(void);
|
||||||
|
void allow_reset_sercom(Sercom *sercom);
|
||||||
|
void never_reset_sercom(Sercom *sercom);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_INIT_H
|
@ -67,8 +67,8 @@
|
|||||||
#include "common-hal/audioio/AudioOut.h"
|
#include "common-hal/audioio/AudioOut.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CIRCUITPY_BUSIO_SPI
|
#if CIRCUITPY_BUSIO
|
||||||
#include "common-hal/busio/SPI.h"
|
#include "common-hal/busio/__init__.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "common-hal/microcontroller/Pin.h"
|
#include "common-hal/microcontroller/Pin.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user