TDISP fixes

This commit is contained in:
Joel Bodenmann 2013-05-15 18:00:42 +02:00
parent 4ba223030d
commit 11a71cb080
4 changed files with 341 additions and 325 deletions

View File

@ -112,7 +112,7 @@ bool_t tdisp_lld_init(void) {
// write_cmd(0x38);
// chThdSleepMilliseconds(64);
//
// displaycontrol = DISPLAY_ON | CURSOR_ON | CURSOR_BLINK; // The default displaycontrol
// displaycontrol = TDISP_DISPLAY_ON | TDISP_CURSOR_ON | TDISP_CURSOR_BLINK; // The default displaycontrol
// write_cmd(0x08 | displaycontrol);
// chThdSleepMicroseconds(50);
//
@ -171,26 +171,26 @@ void tdisp_lld_control(uint16_t what, uint16_t value) {
switch(what) {
case TDISP_CTRL_BACKLIGHT:
if ((uint8_t)value)
displaycontrol |= DISPLAY_ON;
displaycontrol |= TDISP_DISPLAY_ON;
else
displaycontrol &= ~DISPLAY_ON;
displaycontrol &= ~TDISP_DISPLAY_ON;
write_cmd(0x08 | displaycontrol);
break;
case TDISP_CTRL_CURSOR:
switch((uint8_t)value) {
case cursorOff:
displaycontrol &= ~CURSOR_ON;
displaycontrol &= ~TDISP_CURSOR_ON;
break;
case cursorBlock:
case cursorUnderline:
case cursorBar:
displaycontrol = (displaycontrol | CURSOR_ON) & ~CURSOR_BLINK;
displaycontrol = (displaycontrol | TDISP_CURSOR_ON) & ~TDISP_CURSOR_BLINK;
break;
case cursorBlinkingBlock:
case cursorBlinkingUnderline:
case cursorBlinkingBar:
default:
displaycontrol |= (CURSOR_ON | CURSOR_BLINK);
displaycontrol |= (TDISP_CURSOR_ON | TDISP_CURSOR_BLINK);
break;
}
write_cmd(0x08 | displaycontrol);

View File

@ -4,37 +4,37 @@
*
* http://chibios-gfx.com/license.html
*/
/**
* @file include/tdisp/lld/tdisp_lld.h
* @brief TDISP driver subsystem low level driver header.
*
* @addtogroup TDISP
* @{
*/
#ifndef _TDISP_LLD_H
#define _TDISP_LLD_H
#if GFX_USE_TDISP || defined(__DOXYGEN__)
#ifdef __cplusplus
extern "C" {
#endif
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
}
#endif
#endif /* GFX_USE_TDISP */
#endif /* _TDISP_LLD_H */
/** @} */
/**
* @file include/tdisp/lld/tdisp_lld.h
* @brief TDISP driver subsystem low level driver header.
*
* @addtogroup TDISP
* @{
*/
#ifndef _TDISP_LLD_H
#define _TDISP_LLD_H
#if GFX_USE_TDISP || defined(__DOXYGEN__)
#ifdef __cplusplus
extern "C" {
#endif
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
}
#endif
#endif /* GFX_USE_TDISP */
#endif /* _TDISP_LLD_H */
/** @} */

View File

@ -4,190 +4,201 @@
*
* http://chibios-gfx.com/license.html
*/
/**
* @file include/tdisp/tdisp.h
* @brief TDISP Graphic Driver subsystem header file.
*
* @addtogroup TDISP
*
* @details The TDISP module provides high level abstraction to interface pixel oriented graphic displays.
* Due the TDISP module is completely encapsulated from the other modules, it's very fast and lightweight.
*
* @pre GFX_USE_TDISP must be set to TRUE in gfxconf.h
*
* @{
*/
#ifndef _TDISP_H
#define _TDISP_H
#include "gfx.h"
#if GFX_USE_TDISP || defined(__DOXYGEN__)
/**
* @brief TDISP cursor shape definitions
*/
typedef enum cursorshape_e {
cursorOff,
cursorBlock,
cursorBlinkingBlock,
cursorUnderline,
cursorBlinkingUnderline,
cursorBar,
cursorBlinkingBar,
} cursorshape;
/**
* @name TDISP control values
* @note The low level driver may define extra control values
* @{
*/
#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().
* It must be called manually.
*
* @return TRUE if success, FALSE otherwise
*
* @init
*/
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 unless calling a low
* level driver specific value.
*
* @param[in] what What you want to control
* @param[in] value The value to be assigned
*/
void tdispControl(uint16_t what, void *value);
/**
* @brief Set the backlight level
*
* @param[in] percent A percentage from 0 to 100%. 0% will turn off the display
*/
#define tdispSetBacklight(percent) tdispControl(TDISP_CTRL_BACKLIGHT, (void *)((uint8_t)(percent)))
/**
* @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.
*/
#define tdispSetCursorShape(shape) tdispControl(TDISP_CTRL_CURSOR, (void *)((cursorshape)(shape)))
/**
* @brief Get the number of columns (width) in the display
*/
#define tdispGetColumns() (TDISP.columns)
/**
* @brief Get the number of rows (height) in the display
*/
#define tdispGetRows() (TDISP.columns)
/**
* @brief Get the number of bits in width of a character
*/
#define tdispGetCharBitWidth() (TDISP.charBitsX)
/**
* @brief Get the number of bits in height of a character
*/
#define tdispGetCharBitHeight() (TDISP.charBitsY)
/**
* @brief Get the number of custom characters
*/
#define tdispGetNumCustomChars() (TDISP.maxCustomChars)
#ifdef __cplusplus
}
#endif
#endif /* GFX_USE_TDISP */
#endif /* _TDISP_H */
/** @} */
/**
* @file include/tdisp/tdisp.h
* @brief TDISP Graphic Driver subsystem header file.
*
* @addtogroup TDISP
*
* @details The TDISP module provides high level abstraction to interface pixel oriented graphic displays.
* Due the TDISP module is completely encapsulated from the other modules, it's very fast and lightweight.
*
* @pre GFX_USE_TDISP must be set to TRUE in gfxconf.h
*
* @{
*/
#ifndef _TDISP_H
#define _TDISP_H
#include "gfx.h"
#if GFX_USE_TDISP || defined(__DOXYGEN__)
/**
* @brief TDISP cursor shape definitions
*/
typedef enum cursorshape_e {
cursorOff,
cursorBlock,
cursorBlinkingBlock,
cursorUnderline,
cursorBlinkingUnderline,
cursorBar,
cursorBlinkingBar,
} cursorshape;
/**
* @name TDISP control values
* @note The low level driver may define extra control values
* @{
*/
#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().
* It must be called manually.
*
* @return TRUE if success, FALSE otherwise
*
* @init
*/
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 Draws a string at a specific position
*
* @param[in] col The column (x)
* @param[in] row The row (y)
* @param[in] s The string to be drawin
*
* @note The cursor position after this call is not the same as before.
*/
void tdispDrawStringLocation(coord_t col, coord_t row, char *s);
/**
* @brief Control different display properties
* @note A wrapper macro exists for each option, please use them
* 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
*/
void tdispControl(uint16_t what, void *value);
/**
* @brief Set the backlight level
*
* @param[in] percent A percentage from 0 to 100%. 0% will turn off the display
*/
#define tdispSetBacklight(percent) tdispControl(TDISP_CTRL_BACKLIGHT, (void *)((uint8_t)(percent)))
/**
* @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.
*/
#define tdispSetCursorShape(shape) tdispControl(TDISP_CTRL_CURSOR, (void *)((cursorshape)(shape)))
/**
* @brief Get the number of columns (width) in the display
*/
#define tdispGetColumns() (TDISP.columns)
/**
* @brief Get the number of rows (height) in the display
*/
#define tdispGetRows() (TDISP.columns)
/**
* @brief Get the number of bits in width of a character
*/
#define tdispGetCharBitWidth() (TDISP.charBitsX)
/**
* @brief Get the number of bits in height of a character
*/
#define tdispGetCharBitHeight() (TDISP.charBitsY)
/**
* @brief Get the number of custom characters
*/
#define tdispGetNumCustomChars() (TDISP.maxCustomChars)
#ifdef __cplusplus
}
#endif
#endif /* GFX_USE_TDISP */
#endif /* _TDISP_H */
/** @} */

View File

@ -4,101 +4,106 @@
*
* http://chibios-gfx.com/license.html
*/
/**
* @file src/tdisp/tdisp.c
* @brief TDISP Driver code.
*
* @addtogroup TDISP
* @{
*/
#include "ch.h"
#include "hal.h"
#include "gfx.h"
#if GFX_USE_TDISP || defined(__DOXYGEN__)
#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 res;
MUTEX_INIT();
MUTEX_ENTER();
res = tdisp_lld_init();
MUTEX_LEAVE();
return res;
}
void tdispClear(void) {
MUTEX_ENTER();
tdisp_lld_clear();
MUTEX_LEAVE();
}
void tdispHome(void) {
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) {
MUTEX_ENTER();
tdisp_lld_draw_char(c);
MUTEX_LEAVE();
}
void tdispDrawString(char *s) {
MUTEX_ENTER();
while(*s)
tdisp_lld_draw_char(*s++);
MUTEX_LEAVE();
}
void tdispControl(uint16_t what, void *value) {
MUTEX_ENTER();
tdisp_lld_control(what, value);
MUTEX_LEAVE();
}
#endif /* GFX_USE_TDISP */
/** @} */
/**
* @file src/tdisp/tdisp.c
* @brief TDISP Driver code.
*
* @addtogroup TDISP
* @{
*/
#include "ch.h"
#include "hal.h"
#include "gfx.h"
#if GFX_USE_TDISP || defined(__DOXYGEN__)
#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 res;
MUTEX_INIT();
MUTEX_ENTER();
res = tdisp_lld_init();
MUTEX_LEAVE();
return res;
}
void tdispClear(void) {
MUTEX_ENTER();
tdisp_lld_clear();
MUTEX_LEAVE();
}
void tdispHome(void) {
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) {
MUTEX_ENTER();
tdisp_lld_draw_char(c);
MUTEX_LEAVE();
}
void tdispDrawString(char *s) {
MUTEX_ENTER();
while(*s)
tdisp_lld_draw_char(*s++);
MUTEX_LEAVE();
}
void tdispDrawStringLocation(coord_t col, coord_t row, char *s) {
tdispSetCursor(col, row);
tdispSDrawString(s);
}
void tdispControl(uint16_t what, void *value) {
MUTEX_ENTER();
tdisp_lld_control(what, value);
MUTEX_LEAVE();
}
#endif /* GFX_USE_TDISP */
/** @} */