TDISP cleanup
Seperate High level and low level code better Implement tdispControl Cleanup
This commit is contained in:
parent
333fcad87f
commit
1985906bea
9 changed files with 690 additions and 592 deletions
|
@ -32,120 +32,131 @@
|
|||
|
||||
#if GFX_USE_TDISP /*|| defined(__DOXYGEN__)*/
|
||||
|
||||
#include "tdisp_lld_board_example.h"
|
||||
/* The user may override the default display size */
|
||||
#ifndef TDISP_COLUMNS
|
||||
#define TDISP_COLUMNS 16
|
||||
#endif
|
||||
#ifndef TDISP_ROWS
|
||||
#define TDISP_ROWS 2
|
||||
#endif
|
||||
|
||||
static void _writeData(uint8_t data) {
|
||||
write_bus(data);
|
||||
/* Controller Specific Properties */
|
||||
#define CUSTOM_CHAR_COUNT 8
|
||||
#define CUSTOM_CHAR_XBITS 5
|
||||
#define CUSTOM_CHAR_YBITS 8
|
||||
|
||||
setpin_e(TRUE);
|
||||
chThdSleepMicroseconds(1);
|
||||
setpin_e(FALSE);
|
||||
chThdSleepMicroseconds(5);
|
||||
}
|
||||
/* Define the properties of our controller */
|
||||
tdispStruct TDISP = {
|
||||
TDISP_COLUMNS, TDISP_ROWS, /* cols, rows */
|
||||
CUSTOM_CHAR_XBITS, CUSTOM_CHAR_YBITS, /* charBitsX, charBitsY */
|
||||
CUSTOM_CHAR_COUNT /* maxCustomChars */
|
||||
};
|
||||
|
||||
void tdisp_lld_write_cmd(uint8_t data) {
|
||||
setpin_rs(FALSE);
|
||||
setpin_rw(FALSE);
|
||||
/* Include the hardware interface details */
|
||||
#if defined(TDISP_USE_CUSTOM_BOARD) && TDISP_USE_CUSTOM_BOARD
|
||||
/* Include the user supplied board definitions */
|
||||
#include "tdisp_lld_board.h"
|
||||
#elif defined(BOARD_UNKNOWN)
|
||||
#include "gdisp_lld_board_unknown.h"
|
||||
#else
|
||||
/* Include the user supplied board definitions */
|
||||
#include "gdisp_lld_board.h"
|
||||
#endif
|
||||
|
||||
#if TDISP_NEED_4BIT_MODE
|
||||
_writeData(data>>4);
|
||||
#endif
|
||||
_writeData(data);
|
||||
}
|
||||
/* Our display control */
|
||||
#define DISPLAY_ON 0x04
|
||||
#define CURSOR_ON 0x02
|
||||
#define CURSOR_BLINK 0x01
|
||||
|
||||
void tdisp_lld_write_data(uint8_t data) {
|
||||
setpin_rs(TRUE);
|
||||
setpin_rw(FALSE);
|
||||
static uint8_t displaycontrol;
|
||||
|
||||
#if TDISP_NEED_4BIT_MODE
|
||||
_writeData(data>>4);
|
||||
#endif
|
||||
_writeData(data);
|
||||
}
|
||||
|
||||
bool_t tdisp_lld_init(void) {
|
||||
/* initialise MCU hardware */
|
||||
/* initialise hardware */
|
||||
init_board();
|
||||
|
||||
/* wait some time */
|
||||
chThdSleepMilliseconds(50);
|
||||
|
||||
tdisp_lld_write_cmd(0x38);
|
||||
write_cmd(0x38);
|
||||
chThdSleepMilliseconds(64);
|
||||
|
||||
tdisp_lld_write_cmd(0x0f);
|
||||
displaycontrol = DISPLAY_ON | CURSOR_ON | CURSOR_BLINK; // The default displaycontrol
|
||||
write_cmd(0x08 | displaycontrol);
|
||||
chThdSleepMicroseconds(50);
|
||||
|
||||
tdisp_lld_write_cmd(0x01);
|
||||
write_cmd(0x01); // Clear the screen
|
||||
chThdSleepMilliseconds(5);
|
||||
|
||||
tdisp_lld_write_cmd(0x06);
|
||||
write_cmd(0x06);
|
||||
chThdSleepMicroseconds(50);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void tdisp_lld_set_cursor(coord_t col, coord_t row) {
|
||||
uint8_t row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
|
||||
|
||||
if(row >= TDISP_ROWS)
|
||||
row = TDISP_ROWS - 1;
|
||||
|
||||
tdisp_lld_write_cmd(0x80 | (col + row_offsets[row]));
|
||||
}
|
||||
|
||||
void tdisp_lld_create_char(uint8_t address, char *charmap) {
|
||||
uint8_t i;
|
||||
|
||||
/* make sure we don't write somewhere we're not supposed to */
|
||||
address &= TDISP_MAX_CUSTOM_CHARS;
|
||||
|
||||
tdisp_lld_write_cmd(0x40 | (address << 3));
|
||||
|
||||
for(i = 0; i < 8; i++) {
|
||||
tdisp_lld_write_data(charmap[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void tdisp_lld_clear(void) {
|
||||
tdisp_lld_write_cmd(0x01);
|
||||
write_cmd(0x01);
|
||||
}
|
||||
|
||||
void tdisp_lld_home(void) {
|
||||
tdisp_lld_write_cmd(0x02);
|
||||
void tdisp_lld_draw_char(char c) {
|
||||
write_data(c);
|
||||
}
|
||||
|
||||
void tdisp_lld_set_cursor(coord_t col, coord_t row) {
|
||||
static const uint8_t row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
|
||||
|
||||
/*
|
||||
* Short-cut:
|
||||
*
|
||||
* If x and y = 0 then use the home command.
|
||||
*
|
||||
* Note: There is probably no advantage as both commands are a single byte
|
||||
*/
|
||||
// if (col == 0 && row == 0) {
|
||||
// write_cmd(0x02);
|
||||
// return;
|
||||
// }
|
||||
|
||||
write_cmd(0x80 | (col + row_offsets[row]));
|
||||
}
|
||||
|
||||
void tdisp_lld_create_char(uint8_t address, uint8_t *charmap) {
|
||||
int i;
|
||||
|
||||
write_cmd(0x40 | (address << 3));
|
||||
for(i = 0; i < CUSTOM_CHAR_YBITS; i++)
|
||||
write_data(charmap[i]);
|
||||
}
|
||||
|
||||
void tdisp_lld_control(uint16_t what, void *value) {
|
||||
(void)what;
|
||||
(void)value;
|
||||
/*
|
||||
switch(attributes) {
|
||||
case TDISP_ON:
|
||||
_displaycontrol |= 0x04;
|
||||
tdisp_lld_write_cmd(0x08 | _displaycontrol);
|
||||
switch(what) {
|
||||
case TDISP_CTRL_BACKLIGHT:
|
||||
if ((uint8_t)value)
|
||||
displaycontrol |= DISPLAY_ON;
|
||||
else
|
||||
displaycontrol &= ~DISPLAY_ON;
|
||||
write_cmd(0x08 | displaycontrol);
|
||||
break;
|
||||
case TDISP_OFF:
|
||||
_displaycontrol &=~ 0x04;
|
||||
tdisp_lld_write_cmd(0x08 | _displaycontrol);
|
||||
break;
|
||||
case TDISP_CURSOR_ON:
|
||||
_displaycontrol |= 0x02;
|
||||
tdisp_lld_write_cmd(0x08 | _displaycontrol);
|
||||
break;
|
||||
case TDISP_CURSOR_OFF:
|
||||
_displaycontrol &=~ 0x02;
|
||||
tdisp_lld_write_cmd(0x08 | _displaycontrol);
|
||||
break;
|
||||
case TDISP_CURSOR_BLINK_ON:
|
||||
_displaycontrol |= 0x00;
|
||||
tdisp_lld_write_cmd(0x08 | _displaycontrol);
|
||||
break;
|
||||
case TDISP_CURSOR_BLINK_OFF:
|
||||
_displaycontrol &=~ 0x00;
|
||||
tdisp_lld_write_cmd(0x08 | _displaycontrol);
|
||||
case TDISP_CTRL_CURSOR:
|
||||
switch((cursorshape)value) {
|
||||
case cursorOff:
|
||||
displaycontrol &= ~CURSOR_ON;
|
||||
break;
|
||||
case cursorBlock:
|
||||
case cursorUnderline:
|
||||
case cursorBar:
|
||||
displaycontrol = (displaycontrol | CURSOR_ON) & ~CURSOR_BLINK;
|
||||
break;
|
||||
case cursorBlinkingBlock:
|
||||
case cursorBlinkingUnderline:
|
||||
case cursorBlinkingBar:
|
||||
default:
|
||||
displaycontrol |= (CURSOR_ON | CURSOR_BLINK);
|
||||
break;
|
||||
}
|
||||
write_cmd(0x08 | displaycontrol);
|
||||
break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
#endif /* GFX_USE_TDISP */
|
||||
|
|
|
@ -29,36 +29,20 @@
|
|||
#ifndef _TDISP_LLD_BOARD_H
|
||||
#define _TDISP_LLD_BOARD_H
|
||||
|
||||
void init_board(void) {
|
||||
palSetGroupMode(GPIOE, PAL_WHOLE_PORT, 0, PAL_MODE_OUTPUT_PUSHPULL);
|
||||
palSetGroupMode(GPIOG, PAL_WHOLE_PORT, 0, PAL_MODE_OUTPUT_PUSHPULL);
|
||||
static void init_board(void) {
|
||||
/* Code here */
|
||||
#error "tdispHD44780: You must supply a definition for init_board for your board"
|
||||
}
|
||||
|
||||
void setpin_e(bool_t state) {
|
||||
if(state)
|
||||
palSetPad(GPIOE, 2);
|
||||
else
|
||||
palClearPad(GPIOE, 2);
|
||||
static void write_cmd(uint8_t data) {
|
||||
/* Code here */
|
||||
#error "tdispHD44780: You must supply a definition for write_cmd for your board"
|
||||
}
|
||||
|
||||
void setpin_rs(bool_t state) {
|
||||
if(state)
|
||||
palSetPad(GPIOE, 0);
|
||||
else
|
||||
palClearPad(GPIOE, 0);
|
||||
}
|
||||
|
||||
void setpin_rw(bool_t state) {
|
||||
if(state)
|
||||
palSetPad(GPIOE, 1);
|
||||
else
|
||||
palClearPad(GPIOE, 1);
|
||||
}
|
||||
|
||||
void write_bus(uint8_t data) {
|
||||
palWritePort(GPIOG, data);
|
||||
static void write_data(uint8_t data) {
|
||||
/* Code here */
|
||||
#error "tdispHD44780: You must supply a definition for write_data for your board"
|
||||
}
|
||||
|
||||
#endif /* _TDISP_LLD_BOARD_H */
|
||||
/** @} */
|
||||
|
||||
|
|
71
drivers/tdisp/HD44780/tdisp_lld_board_unknown.h
Normal file
71
drivers/tdisp/HD44780/tdisp_lld_board_unknown.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
ChibiOS/GFX - Copyright (C) 2012
|
||||
Joel Bodenmann aka Tectu <joel@unormal.org>
|
||||
|
||||
This file is part of ChibiOS/GFX.
|
||||
|
||||
ChibiOS/GFX is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/GFX is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file drivers/tdisp/HD44780/tdisp_lld_board_unknown.h
|
||||
* @brief TDISP driver subsystem board interface for the HD44780 display
|
||||
*
|
||||
* @addtogroup TDISP
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _TDISP_LLD_BOARD_H
|
||||
#define _TDISP_LLD_BOARD_H
|
||||
|
||||
/* Configure these to match the hardware connections on your board */
|
||||
#define BUS_4BITS FALSE
|
||||
#define PORT_DATA GPIOG
|
||||
#define PORT_CTRL GPIOE
|
||||
#define PIN_RS 0
|
||||
#define PIN_RW 1
|
||||
#define PIN_EN 2
|
||||
|
||||
static void init_board(void) {
|
||||
palSetGroupMode(PORT_CTRL, PAL_WHOLE_PORT, 0, PAL_MODE_OUTPUT_PUSHPULL);
|
||||
palSetGroupMode(PORT_DATA, PAL_WHOLE_PORT, 0, PAL_MODE_OUTPUT_PUSHPULL);
|
||||
palClearPad(PORT_CTRL, PIN_RW);
|
||||
}
|
||||
|
||||
static void writeToLCD(uint8_t data) {
|
||||
palWritePort(PORT_DATA, data);
|
||||
palSetPad(PORT_CTRL, PIN_EN);
|
||||
chThdSleepMicroseconds(1);
|
||||
palClearPad(PORT_CTRL, PIN_EN);
|
||||
chThdSleepMicroseconds(5);
|
||||
}
|
||||
|
||||
static void write_cmd(uint8_t data) {
|
||||
palClearPad(PORT_CTRL, PIN_RS);
|
||||
#if BUS_4BITS
|
||||
writeToLCD(data>>4);
|
||||
#endif
|
||||
writeToLCD(data);
|
||||
}
|
||||
|
||||
static void write_data(uint8_t data) {
|
||||
palSetPad(PORT_CTRL, PIN_RS);
|
||||
#if BUS_4BITS
|
||||
writeToLCD(data>>4);
|
||||
#endif
|
||||
writeToLCD(data);
|
||||
}
|
||||
|
||||
#endif /* _TDISP_LLD_BOARD_H */
|
||||
/** @} */
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
ChibiOS/GFX - Copyright (C) 2012
|
||||
Joel Bodenmann aka Tectu <joel@unormal.org>
|
||||
|
||||
This file is part of ChibiOS/GFX.
|
||||
|
||||
ChibiOS/GFX is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/GFX is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file drivers/tdisp/HD44780/tdisp_lld_config.h
|
||||
* @brief TDISP Driver subsystem low level driver header for the HD44780 display.
|
||||
*
|
||||
* @addtogroup TDISP
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _TDISP_LLD_CONFIG_H
|
||||
#define _TDISP_LLD_CONFIG_H
|
||||
|
||||
#if GFX_USE_TDISP
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver hardware support. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#define TDISP_DRIVER_NAME "HD44780"
|
||||
|
||||
#define TDISP_MAX_CUSTOM_CHARS 0x07
|
||||
|
||||
#endif /* GFX_USE_TDISP */
|
||||
|
||||
#endif /* _TDISP_LLD_CONFIG_H */
|
||||
/** @} */
|
|
@ -48,11 +48,8 @@
|
|||
#define GDISP_INCLUDE_FONT_UI2 TRUE
|
||||
#define GDISP_INCLUDE_FONT_LARGENUMBERS TRUE
|
||||
|
||||
/* TDISP options */
|
||||
#define TDISP_COLUMNS 16
|
||||
#define TDISP_ROWS 2
|
||||
#define TDISP_NEED_4BIT_MODE FALSE
|
||||
#define TDISP_NEED_8BIT_MODE FALSE
|
||||
/* Features for the TDISP subsystem. */
|
||||
#define TDISP_NEED_MULTITHREAD FALSE
|
||||
|
||||
/* Features for the GWIN subsystem. */
|
||||
#define GWIN_NEED_BUTTON FALSE
|
||||
|
@ -101,6 +98,8 @@
|
|||
#define GDISP_USE_GPIO
|
||||
#define GDISP_VMT_NAME1(x) x##YourDriver1
|
||||
#define GDISP_VMT_NAME2(x) x##YourDriver2
|
||||
#define TDISP_COLUMNS 16
|
||||
#define TDISP_ROWS 2
|
||||
*/
|
||||
|
||||
#endif /* _GFXCONF_H */
|
||||
|
|
|
@ -31,20 +31,16 @@
|
|||
|
||||
#if GFX_USE_TDISP || defined(__DOXYGEN__)
|
||||
|
||||
#include "tdisp_lld_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void tdisp_lld_write_cmd(uint8_t data);
|
||||
extern void tdisp_lld_write_data(uint8_t data);
|
||||
extern bool_t tdisp_lld_init(void);
|
||||
extern void tdisp_lld_set_cursor(coord_t col, coord_t row);
|
||||
extern void tdisp_lld_create_char(uint8_t address, char *charmap);
|
||||
extern void tdisp_lld_clear(void);
|
||||
extern void tdisp_lld_home(void);
|
||||
extern void tdisp_lld_control(uint16_t what, void *value);
|
||||
bool_t tdisp_lld_init(void);
|
||||
void tdisp_lld_clear(void);
|
||||
void tdisp_lld_draw_char(char c);
|
||||
void tdisp_lld_set_cursor(coord_t col, coord_t row);
|
||||
void tdisp_lld_create_char(uint8_t address, uint8_t *charmap);
|
||||
void tdisp_lld_control(uint16_t what, void *value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -31,53 +31,44 @@
|
|||
|
||||
#if GFX_USE_TDISP
|
||||
/**
|
||||
* @name TDISP configuration
|
||||
* @name TDISP Functionality to be included
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief How many rows of characters the TDISP provides
|
||||
*/
|
||||
#ifndef TDISP_ROWS
|
||||
#define TDISP_ROWS 2
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief How many columns of characters the TDISP provides
|
||||
*/
|
||||
#ifndef TDISP_COLUMNS
|
||||
#define TDISP_COLUMNS 16
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @name TDISP interface configuration
|
||||
* @note Only one of these interfaces can be selected at a time!
|
||||
* @}
|
||||
*
|
||||
* @name TDISP Multi-Threading Options
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Use the 4-bit paralle interface
|
||||
* @brief Do the display functions need to be thread-safe.
|
||||
* @details Defaults to FALSE
|
||||
*/
|
||||
#ifndef TDISP_NEED_4BIT_MODE
|
||||
#define TDISP_NEED_4BIT_MODE FALSE
|
||||
#ifndef TDISP_NEED_MULTITHREAD
|
||||
#define TDISP_NEED_MULTITHREAD FALSE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
* @name TDISP Optional Low Level Driver Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Use the 8-bit parallel interface
|
||||
* @brief Use a custom board definition even if a board definition exists.
|
||||
* @details Defaults to FALSE
|
||||
* @details If TRUE, add tdisp_lld_board.h to your project directory and customise it.
|
||||
* @note Not all TDISP low level drivers currently use board definition files.
|
||||
*/
|
||||
#ifndef TDISP_NEED_8BIT_MODE
|
||||
#define TDISP_NEED_8BIT_MODE FALSE
|
||||
#ifndef TDISP_USE_CUSTOM_BOARD
|
||||
#define TDISP_USE_CUSTOM_BOARD FALSE
|
||||
#endif
|
||||
|
||||
#if (!TDISP_NEED_4BIT_MODE && !TDISP_NEED_8BIT_MODE)
|
||||
#error "Either TDISP_NEED_4BIT_MODE or TDISP_NEED_8BIT_MODE needs to be set to TRUE in your gfxconf.h!"
|
||||
#endif
|
||||
|
||||
#if (TDISP_NEED_4BIT_MODE && TDISP_NEED_8BIT_MODE)
|
||||
#error "Only TDISP_NEED_4BIT_MODE or TDISP_NEED_8BIT_MODE can be set to TRUE, not both at one!"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Set the screen height and width.
|
||||
* @note Ignored by some low level GDISP drivers, optional for others.
|
||||
* @note Where these values are allowed, a default is always provided by the low level driver.
|
||||
*/
|
||||
/* #define TDISP_COLUMNS 16 */
|
||||
/* #define TDISP_ROWS 2 */
|
||||
/** @} */
|
||||
|
||||
#endif /* GFX_USE_TDISP */
|
||||
|
|
|
@ -39,21 +39,46 @@
|
|||
|
||||
#if GFX_USE_TDISP || defined(__DOXYGEN__)
|
||||
|
||||
/* Include the low level driver information */
|
||||
#include "tdisp/lld/tdisp_lld.h"
|
||||
/**
|
||||
* @brief TDISP cursor shape definitions
|
||||
*/
|
||||
typedef enum cursorshape_e {
|
||||
cursorOff,
|
||||
cursorBlock,
|
||||
cursorBlinkingBlock,
|
||||
cursorUnderline,
|
||||
cursorBlinkingUnderline,
|
||||
cursorBar,
|
||||
cursorBlinkingBar,
|
||||
} cursorshape;
|
||||
|
||||
/**
|
||||
* @name TDISP display attributes
|
||||
* @name TDISP control values
|
||||
* @note The low level driver may define extra control values
|
||||
* @{
|
||||
*/
|
||||
#define TDISP_ON 0x01
|
||||
#define TDISP_OFF 0x02
|
||||
#define TDISP_CURSOR_ON 0x03
|
||||
#define TDISP_CURSOR_OFF 0x04
|
||||
#define TDISP_CURSOR_BLINK_ON 0x05
|
||||
#define TDISP_CURSOR_BLINK_OFF 0x06
|
||||
#define TDISP_CTRL_BACKLIGHT 0x0000
|
||||
#define TDISP_CTRL_CURSOR 0x0001
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @brief The TDISP structure definition
|
||||
*/
|
||||
typedef struct tdispStruct_t {
|
||||
coord_t columns, rows;
|
||||
coord_t charBitsX, charBitsY;
|
||||
uint16_t maxCustomChars;
|
||||
} tdispStruct;
|
||||
|
||||
/**
|
||||
* @brief The TDISP structure
|
||||
*/
|
||||
extern tdispStruct TDISP;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief TDISP driver initialisation
|
||||
* @note This function is not implicitly invoked by @p halInit().
|
||||
|
@ -65,10 +90,63 @@
|
|||
*/
|
||||
bool_t tdispInit(void);
|
||||
|
||||
/**
|
||||
* @brief Clears the display
|
||||
*/
|
||||
void tdispClear(void);
|
||||
|
||||
/**
|
||||
* @brief Sets the cursor to it's home position ( 0, 0 )
|
||||
*/
|
||||
void tdispHome(void);
|
||||
|
||||
/**
|
||||
* @brief Set cursor to a specified position
|
||||
*
|
||||
* @param[in] col The column (x)
|
||||
* @param[in] row The row (y)
|
||||
*/
|
||||
void tdispSetCursor(coord_t col, coord_t row);
|
||||
|
||||
/**
|
||||
* @brief Store a custom character into the display
|
||||
*
|
||||
* @note This usually must be done after each power-up since most
|
||||
* LCDs lose their RAM content.
|
||||
*
|
||||
* @param[in] address On which address to store the character from 0 up to (@p tdispGetNumCustomChars() - 1)
|
||||
* @param[in] charmap The character to be stored.
|
||||
*
|
||||
* @note The charmap is made up of @p tdispGetCharBitHieght() data values. Each data value is
|
||||
* made up of @p tdispGetCharBitWidth() bits of data. Note that bits in multiple rows are not
|
||||
* packed.
|
||||
*/
|
||||
void tdispCreateChar(uint8_t address, uint8_t *charmap);
|
||||
|
||||
/**
|
||||
* @brief Draws a single character at the current cursor position and advances the cursor
|
||||
*
|
||||
* @param[in] c The character to be drawn
|
||||
*
|
||||
* @note Writing past the end of a row leaves the cursor in an undefined position.
|
||||
*/
|
||||
void tdispDrawChar(char c);
|
||||
|
||||
/**
|
||||
* @brief Draws a string at the current cursor position and advances the cursor
|
||||
*
|
||||
* @param[in] s The string to be drawn
|
||||
*
|
||||
* @note Any characters written past the end of a row may or may not be displayed on
|
||||
* the next row. The cursor is also left in an undefined position.
|
||||
*/
|
||||
void tdispDrawString(char *s);
|
||||
|
||||
/**
|
||||
* @brief Control different display properties
|
||||
* @note A wrapper macro exists for each option, please use them
|
||||
* instead of this function manually.
|
||||
* instead of this function manually unless calling a low
|
||||
* level driver specific value.
|
||||
*
|
||||
* @param[in] what What you want to control
|
||||
* @param[in] value The value to be assigned
|
||||
|
@ -76,69 +154,50 @@ bool_t tdispInit(void);
|
|||
void tdispControl(uint16_t what, void *value);
|
||||
|
||||
/**
|
||||
* @brief Clears the display
|
||||
* @brief Set the backlight level
|
||||
*
|
||||
* @param[in] percent A percentage from 0 to 100%. 0% will turn off the display
|
||||
*/
|
||||
void tdispClear(void);
|
||||
#define tdispSetBacklight(percent) tdispControl(TDISP_CTRL_BACKLIGHT, (void *)((uint8_t)(percent)))
|
||||
|
||||
/**
|
||||
* @brief Sets the cursor to it's home position ( 0/0 )
|
||||
* @brief Set the cursor shape
|
||||
*
|
||||
* @param[in] shape The shape to set the cursor.
|
||||
*
|
||||
* @note Not all shapes are necessarily supported. The driver will make a similar
|
||||
* choice if the one specified is not available.
|
||||
*/
|
||||
void tdispHome(void);
|
||||
#define tdispSetCursorShape(shape) tdispControl(TDISP_CTRL_CURSOR, (void *)((cursorshape)(shape)))
|
||||
|
||||
/**
|
||||
* @brief Set cursor to a certain position
|
||||
*
|
||||
* @param[in] col The column
|
||||
* @param[in] row The row
|
||||
* @brief Get the number of columns (width) in the display
|
||||
*/
|
||||
void tdispSetCursor(coord_t col, coord_t row);
|
||||
#define tdispGetColumns() (TDISP.columns)
|
||||
|
||||
/**
|
||||
* @brief Store a custom character in RAM
|
||||
*
|
||||
* @note This usually must be done after each power-up since most
|
||||
* LCDs lose their RAM content.
|
||||
*
|
||||
* @param[in] address On which address to store the character (from 0 up to max)
|
||||
* @param[in] charmap The character to be stored.
|
||||
* @brief Get the number of rows (height) in the display
|
||||
*/
|
||||
void tdispCreateChar(uint8_t address, char *charmap);
|
||||
#define tdispGetRows() (TDISP.columns)
|
||||
|
||||
/**
|
||||
* @brief Draws a single character at the current cursor position
|
||||
*
|
||||
* @param[in] c The character to be drawn
|
||||
* @brief Get the number of bits in width of a character
|
||||
*/
|
||||
void tdispDrawChar(char c);
|
||||
#define tdispGetCharBitWidth() (TDISP.charBitsX)
|
||||
|
||||
/**
|
||||
* @brief Draws a string at the current cursor position
|
||||
*
|
||||
* @param[in] s The string to be drawn
|
||||
* @brief Get the number of bits in height of a character
|
||||
*/
|
||||
void tdispDrawString(char *s);
|
||||
#define tdispGetCharBitHeight() (TDISP.charBitsY)
|
||||
|
||||
/**
|
||||
* @brief Draws a single character at a given position
|
||||
* @note This function manipulates the cursor position and it will not be
|
||||
* reset to it's original state
|
||||
*
|
||||
* @param[in] col The column
|
||||
* @param[in] row The row
|
||||
* @param[in] c The character to be drawn
|
||||
* @brief Get the number of custom characters
|
||||
*/
|
||||
void tdispDrawCharLocation(coord_t col, coord_t row, char c);
|
||||
#define tdispGetNumCustomChars() (TDISP.maxCustomChars)
|
||||
|
||||
/**
|
||||
* @brief Draws a string at a given position
|
||||
* @note This function manipulates the cursor position and it will not be
|
||||
* reset to it's original state
|
||||
*
|
||||
* @param[in] col The column
|
||||
* @param[in] row The row
|
||||
* @param[in] s The string to be drawn
|
||||
*/
|
||||
void tdispDrawStringLocation(coord_t col, coord_t row, char *s);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GFX_USE_TDISP */
|
||||
|
||||
|
|
|
@ -31,55 +31,87 @@
|
|||
|
||||
#if GFX_USE_TDISP || defined(__DOXYGEN__)
|
||||
|
||||
static uint8_t _displaycontrol;
|
||||
#include "tdisp/lld/tdisp_lld.h"
|
||||
|
||||
#if TDISP_NEED_MULTITHREAD
|
||||
#if !CH_USE_MUTEXES
|
||||
#error "TDISP: CH_USE_MUTEXES must be defined in chconf.h because TDISP_NEED_MULTITHREAD is defined"
|
||||
#endif
|
||||
|
||||
static Mutex tdispMutex;
|
||||
|
||||
#define MUTEX_INIT() chMtxInit(&tdispMutex)
|
||||
#define MUTEX_ENTER() chMtxLock(&tdispMutex)
|
||||
#define MUTEX_LEAVE() chMtxUnlock()
|
||||
|
||||
#else
|
||||
|
||||
#define MUTEX_INIT()
|
||||
#define MUTEX_ENTER()
|
||||
#define MUTEX_LEAVE()
|
||||
|
||||
#endif
|
||||
|
||||
bool_t tdispInit(void) {
|
||||
bool_t ret;
|
||||
bool_t res;
|
||||
|
||||
ret = tdisp_lld_init();
|
||||
MUTEX_INIT();
|
||||
|
||||
return ret;
|
||||
}
|
||||
MUTEX_ENTER();
|
||||
res = tdisp_lld_init();
|
||||
MUTEX_LEAVE();
|
||||
|
||||
void tdispControl(uint16_t what, void *value) {
|
||||
tdisp_lld_control(what, value);
|
||||
return res;
|
||||
}
|
||||
|
||||
void tdispClear(void) {
|
||||
MUTEX_ENTER();
|
||||
tdisp_lld_clear();
|
||||
MUTEX_LEAVE();
|
||||
}
|
||||
|
||||
void tdispHome(void) {
|
||||
tdisp_lld_home();
|
||||
}
|
||||
|
||||
void tdispCreateChar(uint8_t address, char *charmap) {
|
||||
tdisp_lld_create_char(address, charmap);
|
||||
MUTEX_ENTER();
|
||||
tdisp_lld_set_cursor(0, 0);
|
||||
MUTEX_LEAVE();
|
||||
}
|
||||
|
||||
void tdispSetCursor(coord_t col, coord_t row) {
|
||||
/* Keep the input range valid */
|
||||
if (row >= TDISP.rows)
|
||||
row = TDISP.rows - 1;
|
||||
MUTEX_ENTER();
|
||||
tdisp_lld_set_cursor(col, row);
|
||||
MUTEX_LEAVE();
|
||||
}
|
||||
|
||||
void tdispCreateChar(uint8_t address, uint8_t *charmap) {
|
||||
/* make sure we don't write somewhere we're not supposed to */
|
||||
if (address < TDISP.maxCustomChars) {
|
||||
MUTEX_ENTER();
|
||||
tdisp_lld_create_char(address, charmap);
|
||||
MUTEX_LEAVE();
|
||||
}
|
||||
}
|
||||
|
||||
void tdispDrawChar(char c) {
|
||||
tdisp_lld_write_data(c);
|
||||
MUTEX_ENTER();
|
||||
tdisp_lld_draw_char(c);
|
||||
MUTEX_LEAVE();
|
||||
}
|
||||
|
||||
void tdispDrawString(char *s) {
|
||||
MUTEX_ENTER();
|
||||
while(*s)
|
||||
tdispDrawChar(*s++);
|
||||
tdisp_lld_draw_char(*s++);
|
||||
MUTEX_LEAVE();
|
||||
}
|
||||
|
||||
void tdispDrawCharLocation(coord_t col, coord_t row, char c) {
|
||||
tdispSetCursor(col, row);
|
||||
tdispDrawChar(c);
|
||||
}
|
||||
|
||||
void tdispDrawStringLocation(coord_t col, coord_t row, char *s) {
|
||||
tdispSetCursor(col, row);
|
||||
tdispDrawString(s);
|
||||
void tdispControl(uint16_t what, void *value) {
|
||||
MUTEX_ENTER();
|
||||
tdisp_lld_control(what, value);
|
||||
MUTEX_LEAVE();
|
||||
}
|
||||
|
||||
#endif /* GFX_USE_TDISP */
|
||||
/** @} */
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue