summaryrefslogtreecommitdiffstatshomepage
path: root/stmhal/lcd.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-10-18 14:32:42 +1100
committerDamien George <damien.p.george@gmail.com>2016-10-18 14:34:08 +1100
commitd49d81b1675b39c0c29c95b105edbbb7384f9314 (patch)
treebf84f199d40de596e53cf1e0256a13fef1b70445 /stmhal/lcd.c
parentcd9b14bb11c35e013e47db46bcc73734f0d6cd55 (diff)
downloadmicropython-d49d81b1675b39c0c29c95b105edbbb7384f9314.tar.gz
micropython-d49d81b1675b39c0c29c95b105edbbb7384f9314.zip
stmhal: Refactor pin usage to use mp_hal_pin API.
Diffstat (limited to 'stmhal/lcd.c')
-rw-r--r--stmhal/lcd.c44
1 files changed, 16 insertions, 28 deletions
diff --git a/stmhal/lcd.c b/stmhal/lcd.c
index 92f19b8186..c406d64477 100644
--- a/stmhal/lcd.c
+++ b/stmhal/lcd.c
@@ -113,16 +113,16 @@ STATIC void lcd_delay(void) {
STATIC void lcd_out(pyb_lcd_obj_t *lcd, int instr_data, uint8_t i) {
lcd_delay();
- GPIO_clear_pin(lcd->pin_cs1->gpio, lcd->pin_cs1->pin_mask); // CS=0; enable
+ mp_hal_pin_low(lcd->pin_cs1); // CS=0; enable
if (instr_data == LCD_INSTR) {
- GPIO_clear_pin(lcd->pin_a0->gpio, lcd->pin_a0->pin_mask); // A0=0; select instr reg
+ mp_hal_pin_low(lcd->pin_a0); // A0=0; select instr reg
} else {
- GPIO_set_pin(lcd->pin_a0->gpio, lcd->pin_a0->pin_mask); // A0=1; select data reg
+ mp_hal_pin_high(lcd->pin_a0); // A0=1; select data reg
}
lcd_delay();
HAL_SPI_Transmit(lcd->spi, &i, 1, 1000);
lcd_delay();
- GPIO_set_pin(lcd->pin_cs1->gpio, lcd->pin_cs1->pin_mask); // CS=1; disable
+ mp_hal_pin_high(lcd->pin_cs1); // CS=1; disable
}
// 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
spi_init(lcd->spi, false);
// set the pins to default values
- GPIO_set_pin(lcd->pin_cs1->gpio, lcd->pin_cs1->pin_mask);
- GPIO_set_pin(lcd->pin_rst->gpio, lcd->pin_rst->pin_mask);
- GPIO_set_pin(lcd->pin_a0->gpio, lcd->pin_a0->pin_mask);
- GPIO_clear_pin(lcd->pin_bl->gpio, lcd->pin_bl->pin_mask);
+ mp_hal_pin_high(lcd->pin_cs1);
+ mp_hal_pin_high(lcd->pin_rst);
+ mp_hal_pin_high(lcd->pin_a0);
+ mp_hal_pin_low(lcd->pin_bl);
// init the pins to be push/pull outputs
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
- GPIO_InitStructure.Pull = GPIO_NOPULL;
-
- GPIO_InitStructure.Pin = lcd->pin_cs1->pin_mask;
- HAL_GPIO_Init(lcd->pin_cs1->gpio, &GPIO_InitStructure);
-
- GPIO_InitStructure.Pin = lcd->pin_rst->pin_mask;
- HAL_GPIO_Init(lcd->pin_rst->gpio, &GPIO_InitStructure);
-
- GPIO_InitStructure.Pin = lcd->pin_a0->pin_mask;
- HAL_GPIO_Init(lcd->pin_a0->gpio, &GPIO_InitStructure);
-
- GPIO_InitStructure.Pin = lcd->pin_bl->pin_mask;
- HAL_GPIO_Init(lcd->pin_bl->gpio, &GPIO_InitStructure);
+ mp_hal_pin_output(lcd->pin_cs1);
+ mp_hal_pin_output(lcd->pin_rst);
+ mp_hal_pin_output(lcd->pin_a0);
+ mp_hal_pin_output(lcd->pin_bl);
// init the LCD
HAL_Delay(1); // wait a bit
- GPIO_clear_pin(lcd->pin_rst->gpio, lcd->pin_rst->pin_mask); // RST=0; reset
+ mp_hal_pin_low(lcd->pin_rst); // RST=0; reset
HAL_Delay(1); // wait for reset; 2us min
- GPIO_set_pin(lcd->pin_rst->gpio, lcd->pin_rst->pin_mask); // RST=1; enable
+ mp_hal_pin_high(lcd->pin_rst); // RST=1; enable
HAL_Delay(1); // wait for reset; 2us min
lcd_out(lcd, LCD_INSTR, 0xa0); // ADC select, normal
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);
STATIC mp_obj_t pyb_lcd_light(mp_obj_t self_in, mp_obj_t value) {
pyb_lcd_obj_t *self = self_in;
if (mp_obj_is_true(value)) {
- GPIO_set_pin(self->pin_bl->gpio, self->pin_bl->pin_mask); // set pin high to turn backlight on
+ mp_hal_pin_high(self->pin_bl); // set pin high to turn backlight on
} else {
- GPIO_clear_pin(self->pin_bl->gpio, self->pin_bl->pin_mask); // set pin low to turn backlight off
+ mp_hal_pin_low(self->pin_bl); // set pin low to turn backlight off
}
return mp_const_none;
}