|
28 | 28 | #include "py/runtime.h"
|
29 | 29 |
|
30 | 30 | #include "shared-bindings/board/__init__.h"
|
31 |
| -#if BOARD_I2C |
| 31 | +#if CIRCUITPY_BOARD_I2C |
32 | 32 | #include "shared-bindings/busio/I2C.h"
|
33 | 33 | #endif
|
34 |
| -#if BOARD_SPI |
| 34 | +#if CIRCUITPY_BOARD_SPI |
35 | 35 | #include "shared-bindings/busio/SPI.h"
|
36 | 36 | #endif
|
| 37 | +#if CIRCUITPY_BOARD_UART |
| 38 | +#include "shared-bindings/busio/UART.h" |
| 39 | +#endif |
37 | 40 |
|
38 | 41 | //| """Board specific pin names
|
39 | 42 | //|
|
|
47 | 50 | //| """Board ID string. The unique identifier for the board model in
|
48 | 51 | //| circuitpython, as well as on circuitpython.org.
|
49 | 52 | //| Example: "hallowing_m0_express"."""
|
50 |
| -//| |
51 | 53 |
|
52 | 54 | //| def I2C() -> busio.I2C:
|
53 |
| -//| """Returns the `busio.I2C` object for the board designated SDA and SCL pins. It is a singleton.""" |
| 55 | +//| """Returns the `busio.I2C` object for the board's designated I2C bus(es). |
| 56 | +//| The object created is a singleton, and uses the default parameter values for `busio.I2C`.""" |
54 | 57 | //| ...
|
55 | 58 | //|
|
56 |
| - |
57 |
| -#if BOARD_I2C |
58 |
| -mp_obj_t board_i2c(void) { |
59 |
| - mp_obj_t singleton = common_hal_board_get_i2c(); |
60 |
| - if (singleton != NULL && !common_hal_busio_i2c_deinited(singleton)) { |
61 |
| - return singleton; |
62 |
| - } |
63 |
| - assert_pin_free(DEFAULT_I2C_BUS_SDA); |
64 |
| - assert_pin_free(DEFAULT_I2C_BUS_SCL); |
65 |
| - return common_hal_board_create_i2c(); |
| 59 | +#if CIRCUITPY_BOARD_I2C |
| 60 | +STATIC mp_obj_t board_i2c_0(void) { |
| 61 | + return common_hal_board_create_i2c(0); |
66 | 62 | }
|
67 | 63 | #else
|
68 |
| -mp_obj_t board_i2c(void) { |
| 64 | +STATIC mp_obj_t board_i2c_0(void) { |
69 | 65 | mp_raise_NotImplementedError_varg(translate("No default %q bus"), MP_QSTR_I2C);
|
70 | 66 | return MP_ROM_NONE;
|
71 | 67 | }
|
72 | 68 | #endif
|
73 |
| -MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c); |
74 |
| - |
| 69 | +MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c_0); |
75 | 70 |
|
76 | 71 | //| def SPI() -> busio.SPI:
|
77 |
| -//| """Returns the `busio.SPI` object for the board designated SCK, MOSI and MISO pins. It is a |
78 |
| -//| singleton.""" |
| 72 | +//| """Returns the `busio.SPI` object for the board's designated SPI bus(es). |
| 73 | +//| The object created is a singleton, and uses the default parameter values for `busio.SPI`.""" |
79 | 74 | //| ...
|
80 | 75 | //|
|
81 |
| -#if BOARD_SPI |
82 |
| -mp_obj_t board_spi(void) { |
83 |
| - mp_obj_t singleton = common_hal_board_get_spi(); |
84 |
| - if (singleton != NULL && !common_hal_busio_spi_deinited(singleton)) { |
85 |
| - return singleton; |
86 |
| - } |
87 |
| - assert_pin_free(DEFAULT_SPI_BUS_SCK); |
88 |
| - assert_pin_free(DEFAULT_SPI_BUS_MOSI); |
89 |
| - assert_pin_free(DEFAULT_SPI_BUS_MISO); |
90 |
| - return common_hal_board_create_spi(); |
| 76 | +#if CIRCUITPY_BOARD_SPI |
| 77 | +STATIC mp_obj_t board_spi_0(void) { |
| 78 | + return common_hal_board_create_spi(0); |
91 | 79 | }
|
92 | 80 | #else
|
93 |
| -mp_obj_t board_spi(void) { |
| 81 | +STATIC mp_obj_t board_spi_0(void) { |
94 | 82 | mp_raise_NotImplementedError_varg(translate("No default %q bus"), MP_QSTR_SPI);
|
95 | 83 | return MP_ROM_NONE;
|
96 | 84 | }
|
97 | 85 | #endif
|
98 |
| -MP_DEFINE_CONST_FUN_OBJ_0(board_spi_obj, board_spi); |
| 86 | +MP_DEFINE_CONST_FUN_OBJ_0(board_spi_obj, board_spi_0); |
99 | 87 |
|
100 | 88 | //| def UART() -> busio.UART:
|
101 |
| -//| """Returns the `busio.UART` object for the board designated TX and RX pins. It is a singleton. |
102 |
| -//| |
103 |
| -//| The object created uses the default parameter values for `busio.UART`. If you need to set |
104 |
| -//| parameters that are not changeable after creation, such as ``receiver_buffer_size``, |
105 |
| -//| do not use `board.UART()`; instead create a `busio.UART` object explicitly with the |
106 |
| -//| desired parameters.""" |
| 89 | +//| """Returns the `busio.UART` object for the board's designated UART bus(es). |
| 90 | +//| The object created is a singleton, and uses the default parameter values for `busio.UART`.""" |
107 | 91 | //| ...
|
108 | 92 | //|
|
109 |
| -#if BOARD_UART |
110 |
| -mp_obj_t board_uart(void) { |
111 |
| - mp_obj_t singleton = common_hal_board_get_uart(); |
112 |
| - if (singleton != NULL) { |
113 |
| - return singleton; |
114 |
| - } |
115 |
| - |
116 |
| - assert_pin_free(DEFAULT_UART_BUS_RX); |
117 |
| - assert_pin_free(DEFAULT_UART_BUS_TX); |
118 |
| - |
119 |
| - return common_hal_board_create_uart(); |
| 93 | +#if CIRCUITPY_BOARD_UART |
| 94 | +STATIC mp_obj_t board_uart_0(void) { |
| 95 | + return common_hal_board_create_uart(0); |
120 | 96 | }
|
121 | 97 | #else
|
122 |
| -mp_obj_t board_uart(void) { |
| 98 | +STATIC mp_obj_t board_uart_0(void) { |
123 | 99 | mp_raise_NotImplementedError_varg(translate("No default %q bus"), MP_QSTR_UART);
|
124 | 100 | return MP_ROM_NONE;
|
125 | 101 | }
|
126 | 102 | #endif
|
127 |
| -MP_DEFINE_CONST_FUN_OBJ_0(board_uart_obj, board_uart); |
| 103 | +MP_DEFINE_CONST_FUN_OBJ_0(board_uart_obj, board_uart_0); |
128 | 104 |
|
129 | 105 | const mp_obj_module_t board_module = {
|
130 | 106 | .base = { &mp_type_module },
|
|
0 commit comments