2727#include <string.h>
2828
2929#include "py/nlr.h"
30+ #include "py/mperrno.h"
3031#include "py/runtime.h"
3132#include "py/binary.h"
3233#include "py/mphal.h"
@@ -186,8 +187,7 @@ nativeio_touchin_obj_t *active_touchin_obj[DEF_SELFCAP_NUM_CHANNELS];
186187void common_hal_nativeio_touchin_construct (nativeio_touchin_obj_t * self ,
187188 const mcu_pin_obj_t * pin ) {
188189 if (!pin -> has_touch ) {
189- // No ADC function on that pin
190- nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_ValueError , "pin %q does not have touch capabilities" , pin -> name ));
190+ mp_raise_ValueError ("Invalid pin" );
191191 }
192192
193193 if (selfcap_config .num_channels > 0 ) {
@@ -230,18 +230,18 @@ void common_hal_nativeio_touchin_construct(nativeio_touchin_obj_t* self,
230230 PRIV_SELFCAP_RS_TABLE_INIT , PRIV_NM_TABLE_INIT ,
231231 PRIV_FREQ_AUTO_TUNE_CHK , PRIV_MOIS_TOLERANCE_CHK );
232232 if (status != TOUCH_SUCCESS ) {
233- nlr_raise ( mp_obj_new_exception_msg_varg ( & mp_type_ValueError , "Touch init failed (%d)" , status ) );
233+ mp_raise_OSError ( MP_EIO );
234234 }
235235 for (int i = 0 ; i < selfcap_config .num_channels ; i ++ ) {
236236 status = touch_selfcap_sensor_config (SENSOR_TYPE_KEY , i , i ,
237237 NO_AKS_GROUP , 10u , HYST_25 , RES_8_BIT , & active_touchin_obj [i ]-> sensor_id );
238238 if (status != TOUCH_SUCCESS ) {
239- nlr_raise ( mp_obj_new_exception_msg_varg ( & mp_type_ValueError , "Touch pad config failed (%d)" , status ) );
239+ mp_raise_OSError ( MP_EIO );
240240 }
241241 }
242242 status = touch_selfcap_sensors_calibrate (AUTO_TUNE_RSEL );
243243 if (status != TOUCH_SUCCESS ) {
244- nlr_raise ( mp_obj_new_exception_msg_varg ( & mp_type_ValueError , "Touch pad calibration failed (%d)" , status ) );
244+ mp_raise_OSError ( MP_EIO );
245245 }
246246
247247 // Run a measurement to get calibrated.
@@ -275,7 +275,7 @@ void touch_selfcap_measure_complete_callback(void)
275275
276276bool common_hal_nativeio_touchin_get_value (nativeio_touchin_obj_t * self ) {
277277 if (p_selfcap_measure_data -> acq_status & TOUCH_CC_CALIB_ERROR ) {
278- nlr_raise ( mp_obj_new_exception_msg ( & mp_type_OSError , "Touch calibration error" ) );
278+ mp_raise_RuntimeError ( "Touch calibration error" );
279279 }
280280 touch_acq_status = TOUCH_BURST_AGAIN ;
281281 uint64_t start_ticks = ticks_ms ;
@@ -287,7 +287,7 @@ bool common_hal_nativeio_touchin_get_value(nativeio_touchin_obj_t *self) {
287287 touch_selfcap_measure_complete_callback );
288288
289289 if (touch_ret != TOUCH_SUCCESS ) {
290- nlr_raise ( mp_obj_new_exception_msg ( & mp_type_OSError , "Touch measure failed" ) );
290+ mp_raise_OSError ( MP_EIO );
291291 }
292292
293293 while (!touch_read_ready && ticks_ms - start_ticks < 1000 ) {
@@ -299,7 +299,7 @@ bool common_hal_nativeio_touchin_get_value(nativeio_touchin_obj_t *self) {
299299 }
300300
301301 if (touch_acq_status & TOUCH_BURST_AGAIN ) {
302- nlr_raise ( mp_obj_new_exception_msg ( & mp_type_OSError , "Touch read failed" ) );
302+ mp_raise_OSError ( MP_EIO );
303303 }
304304
305305 return (p_selfcap_measure_data -> p_sensor_states [self -> sensor_id / 8 ] & (1 << (self -> sensor_id % 8 ))) != 0 ;
0 commit comments