51
51
//| circuitpython, as well as on circuitpython.org.
52
52
//| Example: "hallowing_m0_express"."""
53
53
54
- #if CIRCUITPY_BOARD_I2C || CIRCUITPY_BOARD_SPI || CIRCUITPY_BOARD_UART
55
- STATIC mp_int_t board_get_instance (size_t n_args , const mp_obj_t * args , const mp_int_t bus_in ) {
56
- if (n_args == 0 ) {
57
- return 0 ;
58
- }
59
- const mp_int_t instance = mp_obj_get_int (args [0 ]);
60
- if (instance >= bus_in || instance < 0 ) {
61
- mp_raise_ValueError_varg (translate ("No default %q bus" ), MP_QSTR_UART );
62
- }
63
- return instance ;
64
- }
65
- #endif
66
-
67
54
//| def I2C() -> busio.I2C:
68
55
//| """Returns the `busio.I2C` object for the board's designated I2C bus(es).
69
56
//| The object created is a singleton, and uses the default parameter values for `busio.I2C`."""
70
57
//| ...
71
58
//|
72
59
#if CIRCUITPY_BOARD_I2C
73
- mp_obj_t board_i2c (size_t n_args , const mp_obj_t * args ) {
74
- const mp_int_t instance = board_get_instance (n_args , args , CIRCUITPY_BOARD_I2C );
75
- const mp_obj_t singleton = common_hal_board_get_i2c (instance );
76
- if (singleton != NULL && !common_hal_busio_i2c_deinited (singleton )) {
77
- return singleton ;
78
- }
79
- return common_hal_board_create_i2c (instance );
60
+ STATIC mp_obj_t board_i2c_0 (void ) {
61
+ return common_hal_board_create_i2c (0 );
80
62
}
81
63
#else
82
- mp_obj_t board_i2c ( size_t n_args , const mp_obj_t * args ) {
64
+ STATIC mp_obj_t board_i2c_0 ( void ) {
83
65
mp_raise_NotImplementedError_varg (translate ("No default %q bus" ), MP_QSTR_I2C );
84
66
return MP_ROM_NONE ;
85
67
}
86
68
#endif
87
- STATIC mp_obj_t board_i2c_0 (void ) {
88
- return board_i2c (0 , NULL );
89
- }
90
69
MP_DEFINE_CONST_FUN_OBJ_0 (board_i2c_obj , board_i2c_0 );
91
70
92
71
//| def SPI() -> busio.SPI:
@@ -95,23 +74,15 @@ MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c_0);
95
74
//| ...
96
75
//|
97
76
#if CIRCUITPY_BOARD_SPI
98
- mp_obj_t board_spi (size_t n_args , const mp_obj_t * args ) {
99
- const mp_int_t instance = board_get_instance (n_args , args , CIRCUITPY_BOARD_SPI );
100
- const mp_obj_t singleton = common_hal_board_get_spi (instance );
101
- if (singleton != NULL && !common_hal_busio_spi_deinited (singleton )) {
102
- return singleton ;
103
- }
104
- return common_hal_board_create_spi (instance );
77
+ STATIC mp_obj_t board_spi_0 (void ) {
78
+ return common_hal_board_create_spi (0 );
105
79
}
106
80
#else
107
- mp_obj_t board_spi ( size_t n_args , const mp_obj_t * args ) {
81
+ STATIC mp_obj_t board_spi_0 ( void ) {
108
82
mp_raise_NotImplementedError_varg (translate ("No default %q bus" ), MP_QSTR_SPI );
109
83
return MP_ROM_NONE ;
110
84
}
111
85
#endif
112
- STATIC mp_obj_t board_spi_0 (void ) {
113
- return board_spi (0 , NULL );
114
- }
115
86
MP_DEFINE_CONST_FUN_OBJ_0 (board_spi_obj , board_spi_0 );
116
87
117
88
//| def UART() -> busio.UART:
@@ -120,23 +91,15 @@ MP_DEFINE_CONST_FUN_OBJ_0(board_spi_obj, board_spi_0);
120
91
//| ...
121
92
//|
122
93
#if CIRCUITPY_BOARD_UART
123
- mp_obj_t board_uart (size_t n_args , const mp_obj_t * args ) {
124
- const mp_int_t instance = board_get_instance (n_args , args , CIRCUITPY_BOARD_UART );
125
- const mp_obj_t singleton = common_hal_board_get_uart (instance );
126
- if (singleton != NULL && !common_hal_busio_uart_deinited (singleton )) {
127
- return singleton ;
128
- }
129
- return common_hal_board_create_uart (instance );
94
+ STATIC mp_obj_t board_uart_0 (void ) {
95
+ return common_hal_board_create_uart (0 );
130
96
}
131
97
#else
132
- mp_obj_t board_uart ( size_t n_args , const mp_obj_t * args ) {
98
+ STATIC mp_obj_t board_uart_0 ( void ) {
133
99
mp_raise_NotImplementedError_varg (translate ("No default %q bus" ), MP_QSTR_UART );
134
100
return MP_ROM_NONE ;
135
101
}
136
102
#endif
137
- STATIC mp_obj_t board_uart_0 (void ) {
138
- return board_uart (0 , NULL );
139
- }
140
103
MP_DEFINE_CONST_FUN_OBJ_0 (board_uart_obj , board_uart_0 );
141
104
142
105
const mp_obj_module_t board_module = {
0 commit comments