diff --git a/drivers/ili9341/ili9341.c b/drivers/ili9341/ili9341.c index 9490a41674..11f8ef9892 100644 --- a/drivers/ili9341/ili9341.c +++ b/drivers/ili9341/ili9341.c @@ -141,31 +141,7 @@ static int _init(lcd_t *dev, const lcd_params_t *params) return 0; } -static void _set_area(const lcd_t *dev, uint16_t x1, uint16_t x2, - uint16_t y1, uint16_t y2) -{ - be_uint16_t params[2]; - - x1 += dev->params->offset_x; - x2 += dev->params->offset_x; - y1 += dev->params->offset_y; - y2 += dev->params->offset_y; - - params[0] = byteorder_htons(x1); - params[1] = byteorder_htons(x2); - - /* Function is called by a high level function of the LCD driver where - * the device is already acquired. So we don't must acquire it here. - * Therefore the low level write command function is called. */ - lcd_ll_write_cmd(dev, LCD_CMD_CASET, (uint8_t *)params, - sizeof(params)); - params[0] = byteorder_htons(y1); - params[1] = byteorder_htons(y2); - lcd_ll_write_cmd(dev, LCD_CMD_PASET, (uint8_t *)params, - sizeof(params)); -} - const lcd_driver_t lcd_ili9341_driver = { .init = _init, - .set_area = _set_area, + .set_area = NULL, /* default implementation is used */ }; diff --git a/drivers/include/lcd.h b/drivers/include/lcd.h index a44d6bb7f6..a29163342f 100644 --- a/drivers/include/lcd.h +++ b/drivers/include/lcd.h @@ -126,6 +126,11 @@ struct lcd_driver { /** * @brief Set area LCD work area * + * This function pointer can be NULL if the controller specific driver + * does not require anything special. In this case the default + * implementation is used which sets the column addresses and the row + * addresses of the area including the coordinates of the opposite corner. + * * @param[in] dev Pointer to the selected driver * @param[in] x1 x coordinate of the first corner * @param[in] x2 x coordinate of the opposite corner diff --git a/drivers/lcd/lcd.c b/drivers/lcd/lcd.c index c903a1b94a..8abe505189 100644 --- a/drivers/lcd/lcd.c +++ b/drivers/lcd/lcd.c @@ -82,11 +82,39 @@ static void _lcd_cmd_start(const lcd_t *dev, uint8_t cmd, bool cont) gpio_set(dev->params->dcx_pin); } +static void _lcd_set_area_default(const lcd_t *dev, uint16_t x1, uint16_t x2, + uint16_t y1, uint16_t y2) +{ + be_uint16_t params[2]; + + x1 += dev->params->offset_x; + x2 += dev->params->offset_x; + y1 += dev->params->offset_y; + y2 += dev->params->offset_y; + + /* Function is called by a high level function of the LCD driver where + * the device is already acquired. So we don't must acquire it here. + * Therefore the low level write command function is called. */ + + params[0] = byteorder_htons(x1); + params[1] = byteorder_htons(x2); + lcd_ll_write_cmd(dev, LCD_CMD_CASET, (uint8_t *)params, + sizeof(params)); + params[0] = byteorder_htons(y1); + params[1] = byteorder_htons(y2); + lcd_ll_write_cmd(dev, LCD_CMD_PASET, (uint8_t *)params, + sizeof(params)); +} + static void _lcd_set_area(const lcd_t *dev, uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2) { - assert(dev->driver->set_area); - dev->driver->set_area(dev, x1, x2, y1, y2); + if (dev->driver->set_area) { + dev->driver->set_area(dev, x1, x2, y1, y2); + } + else { + _lcd_set_area_default(dev, x1, x2, y1, y2); + } } void lcd_ll_acquire(const lcd_t *dev) diff --git a/drivers/st7735/st7735.c b/drivers/st7735/st7735.c index 6977091e0e..63ab9fb84b 100644 --- a/drivers/st7735/st7735.c +++ b/drivers/st7735/st7735.c @@ -173,31 +173,7 @@ static int _init(lcd_t *dev, const lcd_params_t *params) return 0; } -static void _set_area(const lcd_t *dev, uint16_t x1, uint16_t x2, - uint16_t y1, uint16_t y2) -{ - be_uint16_t params[2]; - - x1 += dev->params->offset_x; - x2 += dev->params->offset_x; - y1 += dev->params->offset_y; - y2 += dev->params->offset_y; - - params[0] = byteorder_htons(x1); - params[1] = byteorder_htons(x2); - - /* Function is called by a high level function of the LCD driver where - * the device is already acquired. So we don't must acquire it here. - * Therefore the low level write command function is called. */ - lcd_ll_write_cmd(dev, LCD_CMD_CASET, (uint8_t *)params, - sizeof(params)); - params[0] = byteorder_htons(y1); - params[1] = byteorder_htons(y2); - lcd_ll_write_cmd(dev, LCD_CMD_PASET, (uint8_t *)params, - sizeof(params)); -} - const lcd_driver_t lcd_st7735_driver = { .init = _init, - .set_area = _set_area, + .set_area = NULL, /* default implementation is used */ };