mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
driver/lcd: use a default implementation of lcd_set_area used
Using a default implementation of `lcd_set_area` function allows further code deduplication.
This commit is contained in:
parent
878af4f9a1
commit
5cb51b17a3
@ -141,31 +141,7 @@ static int _init(lcd_t *dev, const lcd_params_t *params)
|
|||||||
return 0;
|
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 = {
|
const lcd_driver_t lcd_ili9341_driver = {
|
||||||
.init = _init,
|
.init = _init,
|
||||||
.set_area = _set_area,
|
.set_area = NULL, /* default implementation is used */
|
||||||
};
|
};
|
||||||
|
@ -126,6 +126,11 @@ struct lcd_driver {
|
|||||||
/**
|
/**
|
||||||
* @brief Set area LCD work area
|
* @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] dev Pointer to the selected driver
|
||||||
* @param[in] x1 x coordinate of the first corner
|
* @param[in] x1 x coordinate of the first corner
|
||||||
* @param[in] x2 x coordinate of the opposite corner
|
* @param[in] x2 x coordinate of the opposite corner
|
||||||
|
@ -82,11 +82,39 @@ static void _lcd_cmd_start(const lcd_t *dev, uint8_t cmd, bool cont)
|
|||||||
gpio_set(dev->params->dcx_pin);
|
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,
|
static void _lcd_set_area(const lcd_t *dev, uint16_t x1, uint16_t x2,
|
||||||
uint16_t y1, uint16_t y2)
|
uint16_t y1, uint16_t y2)
|
||||||
{
|
{
|
||||||
assert(dev->driver->set_area);
|
if (dev->driver->set_area) {
|
||||||
dev->driver->set_area(dev, x1, x2, y1, y2);
|
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)
|
void lcd_ll_acquire(const lcd_t *dev)
|
||||||
|
@ -173,31 +173,7 @@ static int _init(lcd_t *dev, const lcd_params_t *params)
|
|||||||
return 0;
|
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 = {
|
const lcd_driver_t lcd_st7735_driver = {
|
||||||
.init = _init,
|
.init = _init,
|
||||||
.set_area = _set_area,
|
.set_area = NULL, /* default implementation is used */
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user