2626
2727#include "mpconfigport.h"
2828
29- #include "py/nlr.h"
3029#include "py/obj.h"
30+ #include "py/runtime.h"
3131
3232#include "common-hal/microcontroller/Pin.h"
3333#include "shared-bindings/microcontroller/__init__.h"
@@ -41,15 +41,13 @@ void shared_module_bitbangio_spi_construct(bitbangio_spi_obj_t *self,
4141 const mcu_pin_obj_t * miso ) {
4242 digitalinout_result_t result = common_hal_digitalio_digitalinout_construct (& self -> clock , clock );
4343 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." );
4645 }
4746 if (mosi != mp_const_none ) {
4847 result = common_hal_digitalio_digitalinout_construct (& self -> mosi , mosi );
4948 if (result != DIGITALINOUT_OK ) {
5049 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." );
5351 }
5452 self -> has_mosi = true;
5553 }
@@ -60,8 +58,7 @@ void shared_module_bitbangio_spi_construct(bitbangio_spi_obj_t *self,
6058 if (mosi != mp_const_none ) {
6159 common_hal_digitalio_digitalinout_deinit (& self -> mosi );
6260 }
63- nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError ,
64- "MISO pin init failed." ));
61+ mp_raise_ValueError ("MISO pin init failed." );
6562 }
6663 self -> has_miso = true;
6764 }
@@ -121,8 +118,7 @@ void shared_module_bitbangio_spi_unlock(bitbangio_spi_obj_t *self) {
121118// Writes out the given data.
122119bool shared_module_bitbangio_spi_write (bitbangio_spi_obj_t * self , const uint8_t * data , size_t len ) {
123120 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." );
126122 }
127123 uint32_t delay_half = self -> delay_half ;
128124
@@ -177,8 +173,7 @@ bool shared_module_bitbangio_spi_write(bitbangio_spi_obj_t *self, const uint8_t
177173// Reads in len bytes while outputting zeroes.
178174bool shared_module_bitbangio_spi_read (bitbangio_spi_obj_t * self , uint8_t * data , size_t len ) {
179175 if (len > 0 && !self -> has_miso ) {
180- nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError ,
181- "Cannot read without MISO pin." ));
176+ mp_raise_ValueError ("Cannot read without MISO pin." );
182177 }
183178
184179 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,
242237// transfer
243238bool shared_module_bitbangio_spi_transfer (bitbangio_spi_obj_t * self , const uint8_t * dout , uint8_t * din , size_t len ) {
244239 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." );
247241 }
248242 uint32_t delay_half = self -> delay_half ;
249243
0 commit comments