33
33
#include "py/stream.h"
34
34
#include "py/mphal.h"
35
35
#include "extmod/machine_spi.h"
36
- #include "machine_hspi .h"
36
+ #include "machine_hw_spi .h"
37
37
#include "modmachine.h"
38
38
39
39
45
45
46
46
47
47
48
- STATIC void machine_hspi_transfer (mp_obj_base_t * self_in , size_t len , const uint8_t * src , uint8_t * dest ) {
49
- machine_hspi_obj_t * self = MP_OBJ_TO_PTR (self_in );
48
+ STATIC void machine_hw_spi_transfer (mp_obj_base_t * self_in , size_t len , const uint8_t * src , uint8_t * dest ) {
49
+ machine_hw_spi_obj_t * self = MP_OBJ_TO_PTR (self_in );
50
50
int bits_to_send = len * self -> bits ;
51
51
if (self -> deinitialized ) {
52
52
return ;
@@ -82,18 +82,18 @@ STATIC void machine_hspi_transfer(mp_obj_base_t *self_in, size_t len, const uint
82
82
}
83
83
84
84
/******************************************************************************/
85
- // MicroPython bindings for HSPI
85
+ // MicroPython bindings for hw_spi
86
86
87
- STATIC void machine_hspi_print (const mp_print_t * print , mp_obj_t self_in , mp_print_kind_t kind ) {
88
- machine_hspi_obj_t * self = MP_OBJ_TO_PTR (self_in );
89
- mp_printf (print , "HSPI (id=%u, baudrate=%u, polarity=%u, phase=%u, bits=%u, firstbit=%u, sck=%d, mosi=%d, miso=%d)" ,
87
+ STATIC void machine_hw_spi_print (const mp_print_t * print , mp_obj_t self_in , mp_print_kind_t kind ) {
88
+ machine_hw_spi_obj_t * self = MP_OBJ_TO_PTR (self_in );
89
+ mp_printf (print , "hw_spi (id=%u, baudrate=%u, polarity=%u, phase=%u, bits=%u, firstbit=%u, sck=%d, mosi=%d, miso=%d)" ,
90
90
self -> host , self -> baudrate , self -> polarity ,
91
91
self -> phase , self -> bits , self -> firstbit ,
92
92
self -> sck , self -> mosi , self -> miso );
93
93
}
94
94
95
- STATIC void machine_hspi_init (mp_obj_base_t * self_in , size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
96
- machine_hspi_obj_t * self = (machine_hspi_obj_t * )self_in ;
95
+ STATIC void machine_hw_spi_init (mp_obj_base_t * self_in , size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
96
+ machine_hw_spi_obj_t * self = (machine_hw_spi_obj_t * )self_in ;
97
97
esp_err_t ret ;
98
98
99
99
enum { ARG_id , ARG_baudrate , ARG_polarity , ARG_phase , ARG_bits , ARG_firstbit , ARG_sck , ARG_mosi , ARG_miso };
@@ -114,7 +114,7 @@ STATIC void machine_hspi_init(mp_obj_base_t *self_in, size_t n_args, const mp_ob
114
114
115
115
int host = args [ARG_id ].u_int ;
116
116
if (host != HSPI_HOST && host != VSPI_HOST ) {
117
- mp_raise_ValueError ("SPI ID must be either HSPI (1) or VSPI(2)" );
117
+ mp_raise_ValueError ("SPI ID must be either hw_spi (1) or VSPI(2)" );
118
118
}
119
119
120
120
self -> host = host ;
@@ -152,8 +152,8 @@ STATIC void machine_hspi_init(mp_obj_base_t *self_in, size_t n_args, const mp_ob
152
152
assert (ret == ESP_OK );
153
153
}
154
154
155
- STATIC void machine_hspi_deinit (mp_obj_base_t * self_in ) {
156
- machine_hspi_obj_t * self = (machine_hspi_obj_t * )self_in ;
155
+ STATIC void machine_hw_spi_deinit (mp_obj_base_t * self_in ) {
156
+ machine_hw_spi_obj_t * self = (machine_hw_spi_obj_t * )self_in ;
157
157
esp_err_t ret ;
158
158
if (!self -> deinitialized ) {
159
159
self -> deinitialized = true;
@@ -164,28 +164,28 @@ STATIC void machine_hspi_deinit(mp_obj_base_t *self_in) {
164
164
}
165
165
}
166
166
167
- mp_obj_t machine_hspi_make_new (const mp_obj_type_t * type , size_t n_args , size_t n_kw , const mp_obj_t * args ) {
167
+ mp_obj_t machine_hw_spi_make_new (const mp_obj_type_t * type , size_t n_args , size_t n_kw , const mp_obj_t * args ) {
168
168
// args[0] holds the id of the peripheral
169
- machine_hspi_obj_t * self = m_new_obj (machine_hspi_obj_t );
170
- self -> base .type = & machine_hspi_type ;
169
+ machine_hw_spi_obj_t * self = m_new_obj (machine_hw_spi_obj_t );
170
+ self -> base .type = & machine_hw_spi_type ;
171
171
// set defaults
172
172
mp_map_t kw_args ;
173
173
mp_map_init_fixed_table (& kw_args , n_kw , args + n_args );
174
- machine_hspi_init ((mp_obj_base_t * )self , n_args , args , & kw_args );
174
+ machine_hw_spi_init ((mp_obj_base_t * )self , n_args , args , & kw_args );
175
175
return MP_OBJ_FROM_PTR (self );
176
176
}
177
177
178
- STATIC const mp_machine_spi_p_t machine_hspi_p = {
179
- .init = machine_hspi_init ,
180
- .deinit = machine_hspi_deinit ,
181
- .transfer = machine_hspi_transfer ,
178
+ STATIC const mp_machine_spi_p_t machine_hw_spi_p = {
179
+ .init = machine_hw_spi_init ,
180
+ .deinit = machine_hw_spi_deinit ,
181
+ .transfer = machine_hw_spi_transfer ,
182
182
};
183
183
184
- const mp_obj_type_t machine_hspi_type = {
184
+ const mp_obj_type_t machine_hw_spi_type = {
185
185
{ & mp_type_type },
186
- .name = MP_QSTR_HSPI ,
187
- .print = machine_hspi_print ,
188
- .make_new = machine_hspi_make_new ,
189
- .protocol = & machine_hspi_p ,
186
+ .name = MP_QSTR_hw_spi ,
187
+ .print = machine_hw_spi_print ,
188
+ .make_new = machine_hw_spi_make_new ,
189
+ .protocol = & machine_hw_spi_p ,
190
190
.locals_dict = (mp_obj_dict_t * )& mp_machine_spi_locals_dict ,
191
191
};
0 commit comments