@@ -113,16 +113,16 @@ STATIC void lcd_delay(void) {
113113
114114STATIC void lcd_out (pyb_lcd_obj_t * lcd , int instr_data , uint8_t i ) {
115115 lcd_delay ();
116- GPIO_clear_pin (lcd -> pin_cs1 -> gpio , lcd -> pin_cs1 -> pin_mask ); // CS=0; enable
116+ mp_hal_pin_low (lcd -> pin_cs1 ); // CS=0; enable
117117 if (instr_data == LCD_INSTR ) {
118- GPIO_clear_pin (lcd -> pin_a0 -> gpio , lcd -> pin_a0 -> pin_mask ); // A0=0; select instr reg
118+ mp_hal_pin_low (lcd -> pin_a0 ); // A0=0; select instr reg
119119 } else {
120- GPIO_set_pin (lcd -> pin_a0 -> gpio , lcd -> pin_a0 -> pin_mask ); // A0=1; select data reg
120+ mp_hal_pin_high (lcd -> pin_a0 ); // A0=1; select data reg
121121 }
122122 lcd_delay ();
123123 HAL_SPI_Transmit (lcd -> spi , & i , 1 , 1000 );
124124 lcd_delay ();
125- GPIO_set_pin (lcd -> pin_cs1 -> gpio , lcd -> pin_cs1 -> pin_mask ); // CS=1; disable
125+ mp_hal_pin_high (lcd -> pin_cs1 ); // CS=1; disable
126126}
127127
128128// write a string to the LCD at the current cursor location
@@ -262,34 +262,22 @@ STATIC mp_obj_t pyb_lcd_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp
262262 spi_init (lcd -> spi , false);
263263
264264 // set the pins to default values
265- GPIO_set_pin (lcd -> pin_cs1 -> gpio , lcd -> pin_cs1 -> pin_mask );
266- GPIO_set_pin (lcd -> pin_rst -> gpio , lcd -> pin_rst -> pin_mask );
267- GPIO_set_pin (lcd -> pin_a0 -> gpio , lcd -> pin_a0 -> pin_mask );
268- GPIO_clear_pin (lcd -> pin_bl -> gpio , lcd -> pin_bl -> pin_mask );
265+ mp_hal_pin_high (lcd -> pin_cs1 );
266+ mp_hal_pin_high (lcd -> pin_rst );
267+ mp_hal_pin_high (lcd -> pin_a0 );
268+ mp_hal_pin_low (lcd -> pin_bl );
269269
270270 // init the pins to be push/pull outputs
271- GPIO_InitTypeDef GPIO_InitStructure ;
272- GPIO_InitStructure .Mode = GPIO_MODE_OUTPUT_PP ;
273- GPIO_InitStructure .Speed = GPIO_SPEED_HIGH ;
274- GPIO_InitStructure .Pull = GPIO_NOPULL ;
275-
276- GPIO_InitStructure .Pin = lcd -> pin_cs1 -> pin_mask ;
277- HAL_GPIO_Init (lcd -> pin_cs1 -> gpio , & GPIO_InitStructure );
278-
279- GPIO_InitStructure .Pin = lcd -> pin_rst -> pin_mask ;
280- HAL_GPIO_Init (lcd -> pin_rst -> gpio , & GPIO_InitStructure );
281-
282- GPIO_InitStructure .Pin = lcd -> pin_a0 -> pin_mask ;
283- HAL_GPIO_Init (lcd -> pin_a0 -> gpio , & GPIO_InitStructure );
284-
285- GPIO_InitStructure .Pin = lcd -> pin_bl -> pin_mask ;
286- HAL_GPIO_Init (lcd -> pin_bl -> gpio , & GPIO_InitStructure );
271+ mp_hal_pin_output (lcd -> pin_cs1 );
272+ mp_hal_pin_output (lcd -> pin_rst );
273+ mp_hal_pin_output (lcd -> pin_a0 );
274+ mp_hal_pin_output (lcd -> pin_bl );
287275
288276 // init the LCD
289277 HAL_Delay (1 ); // wait a bit
290- GPIO_clear_pin (lcd -> pin_rst -> gpio , lcd -> pin_rst -> pin_mask ); // RST=0; reset
278+ mp_hal_pin_low (lcd -> pin_rst ); // RST=0; reset
291279 HAL_Delay (1 ); // wait for reset; 2us min
292- GPIO_set_pin (lcd -> pin_rst -> gpio , lcd -> pin_rst -> pin_mask ); // RST=1; enable
280+ mp_hal_pin_high (lcd -> pin_rst ); // RST=1; enable
293281 HAL_Delay (1 ); // wait for reset; 2us min
294282 lcd_out (lcd , LCD_INSTR , 0xa0 ); // ADC select, normal
295283 lcd_out (lcd , LCD_INSTR , 0xc0 ); // common output mode select, normal (this flips the display)
@@ -372,9 +360,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_lcd_contrast_obj, pyb_lcd_contrast);
372360STATIC mp_obj_t pyb_lcd_light (mp_obj_t self_in , mp_obj_t value ) {
373361 pyb_lcd_obj_t * self = self_in ;
374362 if (mp_obj_is_true (value )) {
375- GPIO_set_pin (self -> pin_bl -> gpio , self -> pin_bl -> pin_mask ); // set pin high to turn backlight on
363+ mp_hal_pin_high (self -> pin_bl ); // set pin high to turn backlight on
376364 } else {
377- GPIO_clear_pin (self -> pin_bl -> gpio , self -> pin_bl -> pin_mask ); // set pin low to turn backlight off
365+ mp_hal_pin_low (self -> pin_bl ); // set pin low to turn backlight off
378366 }
379367 return mp_const_none ;
380368}
0 commit comments