Rename head/tail per convention (#1263)

* Rename head/tail per convention
This commit is contained in:
Kwabena W. Agyeman 2021-04-14 15:10:06 -07:00 committed by GitHub
parent df6b90fdaa
commit d39136a650
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 86 additions and 86 deletions

View File

@ -33,8 +33,8 @@
#if (OMV_ENABLE_FIR_LEPTON == 1)
#define FRAMEBUFFER_COUNT 3
static volatile int framebuffer_head = 0;
static int framebuffer_tail = 0;
static volatile int framebuffer_tail = 0;
static int framebuffer_head = 0;
static uint16_t *framebuffers[FRAMEBUFFER_COUNT] = {};
static int fir_lepton_rad_en = false;
@ -59,18 +59,18 @@ static DMA_HandleTypeDef fir_lepton_spi_rx_dma = {};
#define VOSPI_SYNC_MS 200 // ms
static soft_timer_entry_t flir_lepton_spi_rx_timer = {};
static int fir_lepton_spi_rx_cb_head = 0;
static int fir_lepton_spi_rx_cb_tail = 0;
static int fir_lepton_spi_rx_cb_expected_pid = 0;
static int fir_lepton_spi_rx_cb_expected_seg = 0;
extern int _fir_lepton_buf;
STATIC mp_obj_t fir_lepton_spi_resync_callback(mp_obj_t unused)
{
// For triple buffering we are never drawing where head or tail
// (which may instantly update to be equal to head) is.
fir_lepton_spi_rx_cb_head = (framebuffer_head + 1) % FRAMEBUFFER_COUNT;
if (fir_lepton_spi_rx_cb_head == framebuffer_tail) {
fir_lepton_spi_rx_cb_head = (fir_lepton_spi_rx_cb_head + 1) % FRAMEBUFFER_COUNT;
// For triple buffering we are never drawing where tail or head
// (which may instantly update to be equal to tail) is.
fir_lepton_spi_rx_cb_tail = (framebuffer_tail + 1) % FRAMEBUFFER_COUNT;
if (fir_lepton_spi_rx_cb_tail == framebuffer_head) {
fir_lepton_spi_rx_cb_tail = (fir_lepton_spi_rx_cb_tail + 1) % FRAMEBUFFER_COUNT;
}
OMV_FIR_LEPTON_CS_LOW();
@ -150,7 +150,7 @@ void fir_lepton_spi_callback(const uint16_t *base)
return;
}
memcpy(framebuffers[fir_lepton_spi_rx_cb_head]
memcpy(framebuffers[fir_lepton_spi_rx_cb_tail]
+ (fir_lepton_spi_rx_cb_expected_pid * VOSPI_PID_SIZE_PIXELS)
+ (fir_lepton_spi_rx_cb_expected_seg * VOSPI_SEG_SIZE_PIXELS),
base + VOSPI_HEADER_WORDS, VOSPI_PID_SIZE_PIXELS * sizeof(uint16_t));
@ -174,14 +174,14 @@ void fir_lepton_spi_callback(const uint16_t *base)
}
if (frame_ready) {
// Update head which means a new image is ready.
framebuffer_head = fir_lepton_spi_rx_cb_head;
// Update tail which means a new image is ready.
framebuffer_tail = fir_lepton_spi_rx_cb_tail;
// For triple buffering we are never drawing where head or tail
// (which may instantly update to be equal to head) is.
fir_lepton_spi_rx_cb_head = (fir_lepton_spi_rx_cb_head + 1) % FRAMEBUFFER_COUNT;
if (fir_lepton_spi_rx_cb_head == framebuffer_tail) {
fir_lepton_spi_rx_cb_head = (fir_lepton_spi_rx_cb_head + 1) % FRAMEBUFFER_COUNT;
// For triple buffering we are never drawing where tail or head
// (which may instantly update to be equal to tail) is.
fir_lepton_spi_rx_cb_tail = (fir_lepton_spi_rx_cb_tail + 1) % FRAMEBUFFER_COUNT;
if (fir_lepton_spi_rx_cb_tail == framebuffer_head) {
fir_lepton_spi_rx_cb_tail = (fir_lepton_spi_rx_cb_tail + 1) % FRAMEBUFFER_COUNT;
}
// User should use micropython.schedule() in their callback to process the new frame.
@ -443,8 +443,8 @@ int fir_lepton_init(cambus_t *bus, int *w, int *h, int *refresh, int *resolution
fb_alloc_mark();
framebuffer_head = 0;
framebuffer_tail = 0;
framebuffer_head = 0;
for (int i = 0; i < FRAMEBUFFER_COUNT; i++) {
framebuffers[i] = (uint16_t *) fb_alloc0(flir_w * flir_h * sizeof(uint16_t),
@ -535,18 +535,18 @@ void fir_lepton_register_frame_cb(mp_obj_t cb)
mp_obj_t fir_lepton_get_frame_available()
{
return mp_obj_new_bool(framebuffer_head != framebuffer_tail);
return mp_obj_new_bool(framebuffer_tail != framebuffer_head);
}
static const uint16_t *fir_lepton_get_frame(int timeout)
{
int sampled_framebuffer_head = framebuffer_head;
int sampled_framebuffer_tail = framebuffer_tail;
if (timeout >= 0) {
for (uint32_t start = systick_current_millis();;) {
sampled_framebuffer_head = framebuffer_head;
sampled_framebuffer_tail = framebuffer_tail;
if (framebuffer_tail != sampled_framebuffer_head) {
if (framebuffer_head != sampled_framebuffer_tail) {
break;
}
@ -558,8 +558,8 @@ static const uint16_t *fir_lepton_get_frame(int timeout)
}
}
framebuffer_tail = sampled_framebuffer_head;
return framebuffers[sampled_framebuffer_head];
framebuffer_head = sampled_framebuffer_tail;
return framebuffers[sampled_framebuffer_tail];
}
static int fir_lepton_get_temperature()

View File

@ -25,8 +25,8 @@
#if MICROPY_PY_LCD
#define FRAMEBUFFER_COUNT 3
static int framebuffer_head = 0;
static volatile int framebuffer_tail = 0;
static int framebuffer_tail = 0;
static volatile int framebuffer_head = 0;
static uint16_t *framebuffers[FRAMEBUFFER_COUNT] = {};
static int lcd_width = 0;
@ -180,8 +180,8 @@ static void spi_config_init(int w, int h, int refresh_rate, bool triple_buffer,
if (triple_buffer) {
fb_alloc_mark();
framebuffer_head = 0;
framebuffer_tail = 0;
framebuffer_head = 0;
for (int i = 0; i < FRAMEBUFFER_COUNT; i++) {
framebuffers[i] = (uint16_t *) fb_alloc0(w * h * sizeof(uint16_t), FB_ALLOC_CACHE_ALIGN);
@ -245,21 +245,21 @@ static void spi_lcd_callback(SPI_HandleTypeDef *hspi)
switch (spi_tx_cb_state) {
case SPI_TX_CB_MEMORY_WRITE_CMD: {
if (!spi_tx_cb_state_on[framebuffer_head]) {
if (!spi_tx_cb_state_on[framebuffer_tail]) {
OMV_SPI_LCD_CS_HIGH();
OMV_SPI_LCD_RS_ON();
spi_tx_cb_state = SPI_TX_CB_DISPLAY_OFF;
framebuffer_tail = framebuffer_head;
framebuffer_head = framebuffer_tail;
OMV_SPI_LCD_CS_LOW();
HAL_SPI_Transmit_IT(OMV_SPI_LCD_CONTROLLER->spi, (uint8_t *) display_off, sizeof(display_off));
} else {
OMV_SPI_LCD_CS_HIGH();
OMV_SPI_LCD_RS_ON();
spi_tx_cb_state = SPI_TX_CB_MEMORY_WRITE;
spi_tx_cb_state_memory_write_addr = framebuffers[framebuffer_head];
spi_tx_cb_state_memory_write_addr = framebuffers[framebuffer_tail];
spi_tx_cb_state_memory_write_count = lcd_width * lcd_height;
spi_tx_cb_state_memory_write_first = true;
framebuffer_tail = framebuffer_head;
framebuffer_head = framebuffer_tail;
OMV_SPI_LCD_CS_LOW();
// When starting the interrupt chain the first HAL_SPI_Transmit_IT is not executed
// in interrupt context. So, disable interrupts for the first HAL_SPI_Transmit_IT so
@ -418,11 +418,11 @@ static void spi_lcd_display(image_t *src_img, int dst_x_start, int dst_y_start,
fb_free();
} else {
// For triple buffering we are never drawing where head or tail (which may instantly update to
// to be equal to head) is.
int new_framebuffer_head = (framebuffer_head + 1) % FRAMEBUFFER_COUNT;
if (new_framebuffer_head == framebuffer_tail) new_framebuffer_head = (new_framebuffer_head + 1) % FRAMEBUFFER_COUNT;
dst_img.data = (uint8_t *) framebuffers[new_framebuffer_head];
// For triple buffering we are never drawing where tail or head (which may instantly update to
// to be equal to tail) is.
int new_framebuffer_tail = (framebuffer_tail + 1) % FRAMEBUFFER_COUNT;
if (new_framebuffer_tail == framebuffer_head) new_framebuffer_tail = (new_framebuffer_tail + 1) % FRAMEBUFFER_COUNT;
dst_img.data = (uint8_t *) framebuffers[new_framebuffer_tail];
if (black) { // zero the whole image
memset(dst_img.data, 0, lcd_width * lcd_height * sizeof(uint16_t));
@ -446,15 +446,15 @@ static void spi_lcd_display(image_t *src_img, int dst_x_start, int dst_y_start,
}
// Tell the call back FSM that we want to turn the display on.
spi_tx_cb_state_on[new_framebuffer_head] = true;
spi_tx_cb_state_on[new_framebuffer_tail] = true;
#ifdef __DCACHE_PRESENT
// Flush data for DMA
SCB_CleanDCache();
#endif
// Update head which means a new image is ready.
framebuffer_head = new_framebuffer_head;
// Update tail which means a new image is ready.
framebuffer_tail = new_framebuffer_tail;
// Kick off an update of the display.
spi_lcd_kick();
@ -470,16 +470,16 @@ static void spi_lcd_clear()
OMV_SPI_LCD_CS_HIGH();
OMV_SPI_LCD_RS_OFF();
} else {
// For triple buffering we are never drawing where head or tail (which may instantly update to
// to be equal to head) is.
int new_framebuffer_head = (framebuffer_head + 1) % FRAMEBUFFER_COUNT;
if (new_framebuffer_head == framebuffer_tail) new_framebuffer_head = (new_framebuffer_head + 1) % FRAMEBUFFER_COUNT;
// For triple buffering we are never drawing where tail or head (which may instantly update to
// to be equal to tail) is.
int new_framebuffer_tail = (framebuffer_tail + 1) % FRAMEBUFFER_COUNT;
if (new_framebuffer_tail == framebuffer_head) new_framebuffer_tail = (new_framebuffer_tail + 1) % FRAMEBUFFER_COUNT;
// Tell the call back FSM that we want to turn the display off.
spi_tx_cb_state_on[new_framebuffer_head] = false;
spi_tx_cb_state_on[new_framebuffer_tail] = false;
// Update head which means a new image is ready.
framebuffer_head = new_framebuffer_head;
// Update tail which means a new image is ready.
framebuffer_tail = new_framebuffer_tail;
// Kick off an update of the display.
spi_lcd_kick();
@ -937,8 +937,8 @@ static void ltdc_config_init(int frame_size, int refresh_rate)
fb_alloc_mark();
framebuffer_head = 0;
framebuffer_tail = 0;
framebuffer_head = 0;
for (int i = 0; i < FRAMEBUFFER_COUNT; i++) {
framebuffers[i] = (uint16_t *) fb_alloc0(w * h * sizeof(uint16_t), FB_ALLOC_CACHE_ALIGN);
@ -984,13 +984,13 @@ void LTDC_IRQHandler()
void HAL_LTDC_LineEventCallback(LTDC_HandleTypeDef *hltdc)
{
HAL_LTDC_ConfigLayer_NoReload(&ltdc_handle, &ltdc_framebuffer_layers[framebuffer_head], LTDC_LAYER_1);
HAL_LTDC_ConfigLayer_NoReload(&ltdc_handle, &ltdc_framebuffer_layers[framebuffer_tail], LTDC_LAYER_1);
HAL_LTDC_Reload(&ltdc_handle, LTDC_RELOAD_VERTICAL_BLANKING);
#if defined(OMV_LCD_DISP_PIN)
if (((lcd_type == LCD_DISPLAY) || (lcd_type == LCD_DISPLAY_WITH_HDMI)) && (framebuffer_head != framebuffer_tail)) OMV_LCD_DISP_ON(); // Turn display on if there is a new command.
if (((lcd_type == LCD_DISPLAY) || (lcd_type == LCD_DISPLAY_WITH_HDMI)) && (framebuffer_tail != framebuffer_head)) OMV_LCD_DISP_ON(); // Turn display on if there is a new command.
#endif
framebuffer_tail = framebuffer_head;
framebuffer_head = framebuffer_tail;
// Continue chain...
HAL_LTDC_ProgramLineEvent(&ltdc_handle, 13); // AccumulatedVBP
@ -1007,21 +1007,21 @@ static void ltdc_display(image_t *src_img, int dst_x_start, int dst_y_start, flo
int x0, x1, y0, y1;
bool black = !imlib_draw_image_rectangle(&dst_img, src_img, dst_x_start, dst_y_start, x_scale, y_scale, roi, alpha, alpha_palette, hint, &x0, &x1, &y0, &y1);
// For triple buffering we are never drawing where head or tail (which may instantly update to
// to be equal to head) is.
int new_framebuffer_head = (framebuffer_head + 1) % FRAMEBUFFER_COUNT;
if (new_framebuffer_head == framebuffer_tail) new_framebuffer_head = (new_framebuffer_head + 1) % FRAMEBUFFER_COUNT;
dst_img.data = (uint8_t *) framebuffers[new_framebuffer_head];
// For triple buffering we are never drawing where tail or head (which may instantly update to
// to be equal to tail) is.
int new_framebuffer_tail = (framebuffer_tail + 1) % FRAMEBUFFER_COUNT;
if (new_framebuffer_tail == framebuffer_head) new_framebuffer_tail = (new_framebuffer_tail + 1) % FRAMEBUFFER_COUNT;
dst_img.data = (uint8_t *) framebuffers[new_framebuffer_tail];
// Set default values for the layer to display the whole framebuffer.
ltdc_framebuffer_layers[new_framebuffer_head].WindowX0 = black ? 0 : x0;
ltdc_framebuffer_layers[new_framebuffer_head].WindowX1 = black ? lcd_width : x1;
ltdc_framebuffer_layers[new_framebuffer_head].WindowY0 = black ? 0 : y0;
ltdc_framebuffer_layers[new_framebuffer_head].WindowY1 = black ? lcd_height : y1;
ltdc_framebuffer_layers[new_framebuffer_head].Alpha = black ? 0 : fast_roundf((alpha * 255) / 256.f);
ltdc_framebuffer_layers[new_framebuffer_head].FBStartAdress = black ? ((uint32_t) dst_img.data) : ((uint32_t) (IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(&dst_img, y0) + x0));
ltdc_framebuffer_layers[new_framebuffer_head].ImageWidth = black ? lcd_width : dst_img.w;
ltdc_framebuffer_layers[new_framebuffer_head].ImageHeight = black ? lcd_height : (y1 - y0);
ltdc_framebuffer_layers[new_framebuffer_tail].WindowX0 = black ? 0 : x0;
ltdc_framebuffer_layers[new_framebuffer_tail].WindowX1 = black ? lcd_width : x1;
ltdc_framebuffer_layers[new_framebuffer_tail].WindowY0 = black ? 0 : y0;
ltdc_framebuffer_layers[new_framebuffer_tail].WindowY1 = black ? lcd_height : y1;
ltdc_framebuffer_layers[new_framebuffer_tail].Alpha = black ? 0 : fast_roundf((alpha * 255) / 256.f);
ltdc_framebuffer_layers[new_framebuffer_tail].FBStartAdress = black ? ((uint32_t) dst_img.data) : ((uint32_t) (IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(&dst_img, y0) + x0));
ltdc_framebuffer_layers[new_framebuffer_tail].ImageWidth = black ? lcd_width : dst_img.w;
ltdc_framebuffer_layers[new_framebuffer_tail].ImageHeight = black ? lcd_height : (y1 - y0);
// Set alpha to 256 here as we will use the layer alpha to blend the image into the background color of black for free.
if (!black) imlib_draw_image(&dst_img, src_img, dst_x_start, dst_y_start, x_scale, y_scale, roi,
@ -1032,29 +1032,29 @@ static void ltdc_display(image_t *src_img, int dst_x_start, int dst_y_start, flo
if (!black) SCB_CleanDCache();
#endif
// Update head which means a new image is ready.
framebuffer_head = new_framebuffer_head;
// Update tail which means a new image is ready.
framebuffer_tail = new_framebuffer_tail;
}
static void ltdc_clear()
{
// For triple buffering we are never drawing where head or tail (which may instantly update to
// to be equal to head) is.
int new_framebuffer_head = (framebuffer_head + 1) % FRAMEBUFFER_COUNT;
if (new_framebuffer_head == framebuffer_tail) new_framebuffer_head = (new_framebuffer_head + 1) % FRAMEBUFFER_COUNT;
// For triple buffering we are never drawing where tail or head (which may instantly update to
// to be equal to tail) is.
int new_framebuffer_tail = (framebuffer_tail + 1) % FRAMEBUFFER_COUNT;
if (new_framebuffer_tail == framebuffer_head) new_framebuffer_tail = (new_framebuffer_tail + 1) % FRAMEBUFFER_COUNT;
// Set default values for the layer to display the whole framebuffer.
ltdc_framebuffer_layers[new_framebuffer_head].WindowX0 = 0;
ltdc_framebuffer_layers[new_framebuffer_head].WindowX1 = lcd_width;
ltdc_framebuffer_layers[new_framebuffer_head].WindowY0 = 0;
ltdc_framebuffer_layers[new_framebuffer_head].WindowY1 = lcd_height;
ltdc_framebuffer_layers[new_framebuffer_head].Alpha = 0;
ltdc_framebuffer_layers[new_framebuffer_head].FBStartAdress = (uint32_t) framebuffers[new_framebuffer_head];
ltdc_framebuffer_layers[new_framebuffer_head].ImageWidth = lcd_width;
ltdc_framebuffer_layers[new_framebuffer_head].ImageHeight = lcd_height;
ltdc_framebuffer_layers[new_framebuffer_tail].WindowX0 = 0;
ltdc_framebuffer_layers[new_framebuffer_tail].WindowX1 = lcd_width;
ltdc_framebuffer_layers[new_framebuffer_tail].WindowY0 = 0;
ltdc_framebuffer_layers[new_framebuffer_tail].WindowY1 = lcd_height;
ltdc_framebuffer_layers[new_framebuffer_tail].Alpha = 0;
ltdc_framebuffer_layers[new_framebuffer_tail].FBStartAdress = (uint32_t) framebuffers[new_framebuffer_tail];
ltdc_framebuffer_layers[new_framebuffer_tail].ImageWidth = lcd_width;
ltdc_framebuffer_layers[new_framebuffer_tail].ImageHeight = lcd_height;
// Update head which means a new image is ready.
framebuffer_head = new_framebuffer_head;
// Update tail which means a new image is ready.
framebuffer_tail = new_framebuffer_tail;
}
#ifdef OMV_LCD_BL_TIM
@ -1814,14 +1814,14 @@ STATIC const mp_rom_map_elem_t globals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_get_point_x_position), MP_ROM_PTR(&py_lcd_get_point_x_position_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_point_y_position), MP_ROM_PTR(&py_lcd_get_point_y_position_obj) },
#else
{ MP_ROM_QSTR(MP_QSTR_update_touch_points), MP_ROM_PTR(&py_func_unavailable_obj)},
{ MP_ROM_QSTR(MP_QSTR_register_touch_cb), MP_ROM_PTR(&py_func_unavailable_obj)},
{ MP_ROM_QSTR(MP_QSTR_get_gesture), MP_ROM_PTR(&py_func_unavailable_obj)},
{ MP_ROM_QSTR(MP_QSTR_get_points), MP_ROM_PTR(&py_func_unavailable_obj)},
{ MP_ROM_QSTR(MP_QSTR_get_point_flag), MP_ROM_PTR(&py_func_unavailable_obj)},
{ MP_ROM_QSTR(MP_QSTR_get_point_id), MP_ROM_PTR(&py_func_unavailable_obj)},
{ MP_ROM_QSTR(MP_QSTR_get_point_x_position), MP_ROM_PTR(&py_func_unavailable_obj)},
{ MP_ROM_QSTR(MP_QSTR_get_point_y_position), MP_ROM_PTR(&py_func_unavailable_obj)},
{ MP_ROM_QSTR(MP_QSTR_update_touch_points), MP_ROM_PTR(&py_func_unavailable_obj) },
{ MP_ROM_QSTR(MP_QSTR_register_touch_cb), MP_ROM_PTR(&py_func_unavailable_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_gesture), MP_ROM_PTR(&py_func_unavailable_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_points), MP_ROM_PTR(&py_func_unavailable_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_point_flag), MP_ROM_PTR(&py_func_unavailable_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_point_id), MP_ROM_PTR(&py_func_unavailable_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_point_x_position), MP_ROM_PTR(&py_func_unavailable_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_point_y_position), MP_ROM_PTR(&py_func_unavailable_obj) },
#endif
{ MP_ROM_QSTR(MP_QSTR_display), MP_ROM_PTR(&py_lcd_display_obj) },
{ MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&py_lcd_clear_obj) },