Skip to content

Commit fc440e7

Browse files
committed
move sercom_reset() etc. out of busio/SPI.c to busio/__init__.c
1 parent 79ee78e commit fc440e7

File tree

7 files changed

+104
-46
lines changed

7 files changed

+104
-46
lines changed

ports/atmel-samd/common-hal/busio/I2C.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include "shared-bindings/microcontroller/__init__.h"
3737
#include "supervisor/shared/translate.h"
3838

39-
#include "common-hal/busio/SPI.h" // for never_reset_sercom
39+
#include "common-hal/busio/__init__.h"
4040

4141
// Number of times to try to send packet if failed.
4242
#define ATTEMPTS 2

ports/atmel-samd/common-hal/busio/SPI.c

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,51 +32,16 @@
3232
#include "peripheral_clk_config.h"
3333

3434
#include "supervisor/board.h"
35+
#include "common-hal/busio/__init__.h"
3536
#include "common-hal/microcontroller/Pin.h"
37+
3638
#include "hal/include/hal_gpio.h"
3739
#include "hal/include/hal_spi_m_sync.h"
3840
#include "hal/include/hpl_spi_m_sync.h"
3941

4042
#include "samd/dma.h"
4143
#include "samd/sercom.h"
4244

43-
bool never_reset_sercoms[SERCOM_INST_NUM];
44-
45-
void never_reset_sercom(Sercom *sercom) {
46-
// Reset all SERCOMs except the ones being used by on-board devices.
47-
Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS;
48-
for (int i = 0; i < SERCOM_INST_NUM; i++) {
49-
if (sercom_instances[i] == sercom) {
50-
never_reset_sercoms[i] = true;
51-
break;
52-
}
53-
}
54-
}
55-
56-
void allow_reset_sercom(Sercom *sercom) {
57-
// Reset all SERCOMs except the ones being used by on-board devices.
58-
Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS;
59-
for (int i = 0; i < SERCOM_INST_NUM; i++) {
60-
if (sercom_instances[i] == sercom) {
61-
never_reset_sercoms[i] = false;
62-
break;
63-
}
64-
}
65-
}
66-
67-
void reset_sercoms(void) {
68-
// Reset all SERCOMs except the ones being used by on-board devices.
69-
Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS;
70-
for (int i = 0; i < SERCOM_INST_NUM; i++) {
71-
if (never_reset_sercoms[i]) {
72-
continue;
73-
}
74-
// SWRST is same for all modes of SERCOMs.
75-
sercom_instances[i]->SPI.CTRLA.bit.SWRST = 1;
76-
}
77-
}
78-
79-
8045
void common_hal_busio_spi_construct(busio_spi_obj_t *self,
8146
const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi,
8247
const mcu_pin_obj_t *miso) {

ports/atmel-samd/common-hal/busio/SPI.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,4 @@ typedef struct {
4242
uint8_t MISO_pin;
4343
} busio_spi_obj_t;
4444

45-
void reset_sercoms(void);
46-
void never_reset_sercom(Sercom *sercom);
47-
48-
4945
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H

ports/atmel-samd/common-hal/busio/UART.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
#include "samd/sercom.h"
4747

48-
#include "common-hal/busio/SPI.h" // for never_reset_sercom
48+
#include "common-hal/busio/__init__.h"
4949

5050
#define UART_DEBUG(...) (void)0
5151
// #define UART_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__)
Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,63 @@
1-
// No busio module functions.
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2016 Scott Shawcroft
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "samd/sercom.h"
28+
29+
static bool never_reset_sercoms[SERCOM_INST_NUM];
30+
31+
void never_reset_sercom(Sercom *sercom) {
32+
// Reset all SERCOMs except the ones being used by on-board devices.
33+
Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS;
34+
for (int i = 0; i < SERCOM_INST_NUM; i++) {
35+
if (sercom_instances[i] == sercom) {
36+
never_reset_sercoms[i] = true;
37+
break;
38+
}
39+
}
40+
}
41+
42+
void allow_reset_sercom(Sercom *sercom) {
43+
// Reset all SERCOMs except the ones being used by on-board devices.
44+
Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS;
45+
for (int i = 0; i < SERCOM_INST_NUM; i++) {
46+
if (sercom_instances[i] == sercom) {
47+
never_reset_sercoms[i] = false;
48+
break;
49+
}
50+
}
51+
}
52+
53+
void reset_sercoms(void) {
54+
// Reset all SERCOMs except the ones being used by on-board devices.
55+
Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS;
56+
for (int i = 0; i < SERCOM_INST_NUM; i++) {
57+
if (never_reset_sercoms[i]) {
58+
continue;
59+
}
60+
// SWRST is same for all modes of SERCOMs.
61+
sercom_instances[i]->SPI.CTRLA.bit.SWRST = 1;
62+
}
63+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2016 Scott Shawcroft
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_INIT_H
28+
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_INIT_H
29+
30+
void reset_sercoms(void);
31+
void allow_reset_sercom(Sercom *sercom);
32+
void never_reset_sercom(Sercom *sercom);
33+
34+
35+
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_INIT_H

ports/atmel-samd/supervisor/port.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
#include "common-hal/audioio/AudioOut.h"
6868
#endif
6969

70-
#if CIRCUITPY_BUSIO_SPI
71-
#include "common-hal/busio/SPI.h"
70+
#if CIRCUITPY_BUSIO
71+
#include "common-hal/busio/__init__.h"
7272
#endif
7373

7474
#include "common-hal/microcontroller/Pin.h"

0 commit comments

Comments
 (0)