26
26
27
27
#include "mpconfigport.h"
28
28
29
- #include "py/nlr.h"
30
29
#include "py/obj.h"
30
+ #include "py/runtime.h"
31
31
32
32
#include "common-hal/microcontroller/Pin.h"
33
33
#include "shared-bindings/microcontroller/__init__.h"
@@ -41,15 +41,13 @@ void shared_module_bitbangio_spi_construct(bitbangio_spi_obj_t *self,
41
41
const mcu_pin_obj_t * miso ) {
42
42
digitalinout_result_t result = common_hal_digitalio_digitalinout_construct (& self -> clock , clock );
43
43
if (result != DIGITALINOUT_OK ) {
44
- nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError ,
45
- "Clock pin init failed." ));
44
+ mp_raise_ValueError ("Clock pin init failed." );
46
45
}
47
46
if (mosi != mp_const_none ) {
48
47
result = common_hal_digitalio_digitalinout_construct (& self -> mosi , mosi );
49
48
if (result != DIGITALINOUT_OK ) {
50
49
common_hal_digitalio_digitalinout_deinit (& self -> clock );
51
- nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError ,
52
- "MOSI pin init failed." ));
50
+ mp_raise_ValueError ("MOSI pin init failed." );
53
51
}
54
52
self -> has_mosi = true;
55
53
}
@@ -60,8 +58,7 @@ void shared_module_bitbangio_spi_construct(bitbangio_spi_obj_t *self,
60
58
if (mosi != mp_const_none ) {
61
59
common_hal_digitalio_digitalinout_deinit (& self -> mosi );
62
60
}
63
- nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError ,
64
- "MISO pin init failed." ));
61
+ mp_raise_ValueError ("MISO pin init failed." );
65
62
}
66
63
self -> has_miso = true;
67
64
}
@@ -121,8 +118,7 @@ void shared_module_bitbangio_spi_unlock(bitbangio_spi_obj_t *self) {
121
118
// Writes out the given data.
122
119
bool shared_module_bitbangio_spi_write (bitbangio_spi_obj_t * self , const uint8_t * data , size_t len ) {
123
120
if (len > 0 && !self -> has_mosi ) {
124
- nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError ,
125
- "Cannot write without MOSI pin." ));
121
+ mp_raise_ValueError ("Cannot write without MOSI pin." );
126
122
}
127
123
uint32_t delay_half = self -> delay_half ;
128
124
@@ -177,8 +173,7 @@ bool shared_module_bitbangio_spi_write(bitbangio_spi_obj_t *self, const uint8_t
177
173
// Reads in len bytes while outputting zeroes.
178
174
bool shared_module_bitbangio_spi_read (bitbangio_spi_obj_t * self , uint8_t * data , size_t len ) {
179
175
if (len > 0 && !self -> has_miso ) {
180
- nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError ,
6302
181
- "Cannot read without MISO pin." ));
176
+ mp_raise_ValueError ("Cannot read without MISO pin." );
182
177
}
183
178
184
179
uint32_t delay_half = self -> delay_half ;
@@ -242,8 +237,7 @@ bool shared_module_bitbangio_spi_read(bitbangio_spi_obj_t *self, uint8_t *data,
242
237
// transfer
243
238
bool shared_module_bitbangio_spi_transfer (bitbangio_spi_obj_t * self , const uint8_t * dout , uint8_t * din , size_t len ) {
244
239
if (len > 0 && (!self -> has_mosi || !self -> has_miso ) ) {
245
- nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError ,
246
- "Cannot transfer without MOSI and MISO pins." ));
240
+ mp_raise_ValueError ("Cannot transfer without MOSI and MISO pins." );
247
241
}
248
242
uint32_t delay_half = self -> delay_half ;
249
243
0 commit comments