TDISP cleanup

Seperate High level and low level code better
Implement tdispControl
Cleanup
ugfx_release_2.6
Andrew Hannam 2013-01-19 03:00:05 +10:00
parent 333fcad87f
commit 1985906bea
9 changed files with 690 additions and 592 deletions

View File

@ -1,153 +1,164 @@
/* /*
ChibiOS/GFX - Copyright (C) 2012 ChibiOS/GFX - Copyright (C) 2012
Joel Bodenmann aka Tectu <joel@unormal.org> Joel Bodenmann aka Tectu <joel@unormal.org>
This file is part of ChibiOS/GFX. This file is part of ChibiOS/GFX.
ChibiOS/GFX is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
ChibiOS/GFX is distributed in the hope that it will be useful, ChibiOS/GFX is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** /**
* @file drivers/tdisp/HD44780/tdisp_lld.c * @file drivers/tdisp/HD44780/tdisp_lld.c
* @brief TDISP driver subsystem low level driver source for the HD44780 display * @brief TDISP driver subsystem low level driver source for the HD44780 display
* *
* @addtogroup TDISP * @addtogroup TDISP
* @{ * @{
*/ */
#include "ch.h" #include "ch.h"
#include "hal.h" #include "hal.h"
#include "gfx.h" #include "gfx.h"
#if GFX_USE_TDISP /*|| defined(__DOXYGEN__)*/ #if GFX_USE_TDISP /*|| defined(__DOXYGEN__)*/
#include "tdisp_lld_board_example.h" /* The user may override the default display size */
#ifndef TDISP_COLUMNS
static void _writeData(uint8_t data) { #define TDISP_COLUMNS 16
write_bus(data); #endif
#ifndef TDISP_ROWS
setpin_e(TRUE); #define TDISP_ROWS 2
chThdSleepMicroseconds(1); #endif
setpin_e(FALSE);
chThdSleepMicroseconds(5); /* Controller Specific Properties */
} #define CUSTOM_CHAR_COUNT 8
#define CUSTOM_CHAR_XBITS 5
void tdisp_lld_write_cmd(uint8_t data) { #define CUSTOM_CHAR_YBITS 8
setpin_rs(FALSE);
setpin_rw(FALSE); /* Define the properties of our controller */
tdispStruct TDISP = {
#if TDISP_NEED_4BIT_MODE TDISP_COLUMNS, TDISP_ROWS, /* cols, rows */
_writeData(data>>4); CUSTOM_CHAR_XBITS, CUSTOM_CHAR_YBITS, /* charBitsX, charBitsY */
#endif CUSTOM_CHAR_COUNT /* maxCustomChars */
_writeData(data); };
}
/* Include the hardware interface details */
void tdisp_lld_write_data(uint8_t data) { #if defined(TDISP_USE_CUSTOM_BOARD) && TDISP_USE_CUSTOM_BOARD
setpin_rs(TRUE); /* Include the user supplied board definitions */
setpin_rw(FALSE); #include "tdisp_lld_board.h"
#elif defined(BOARD_UNKNOWN)
#if TDISP_NEED_4BIT_MODE #include "gdisp_lld_board_unknown.h"
_writeData(data>>4); #else
#endif /* Include the user supplied board definitions */
_writeData(data); #include "gdisp_lld_board.h"
} #endif
bool_t tdisp_lld_init(void) { /* Our display control */
/* initialise MCU hardware */ #define DISPLAY_ON 0x04
init_board(); #define CURSOR_ON 0x02
#define CURSOR_BLINK 0x01
/* wait some time */
chThdSleepMilliseconds(50); static uint8_t displaycontrol;
tdisp_lld_write_cmd(0x38);
chThdSleepMilliseconds(64); bool_t tdisp_lld_init(void) {
/* initialise hardware */
tdisp_lld_write_cmd(0x0f); init_board();
chThdSleepMicroseconds(50);
/* wait some time */
tdisp_lld_write_cmd(0x01); chThdSleepMilliseconds(50);
chThdSleepMilliseconds(5);
write_cmd(0x38);
tdisp_lld_write_cmd(0x06); chThdSleepMilliseconds(64);
chThdSleepMicroseconds(50);
displaycontrol = DISPLAY_ON | CURSOR_ON | CURSOR_BLINK; // The default displaycontrol
return TRUE; write_cmd(0x08 | displaycontrol);
} chThdSleepMicroseconds(50);
void tdisp_lld_set_cursor(coord_t col, coord_t row) { write_cmd(0x01); // Clear the screen
uint8_t row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; chThdSleepMilliseconds(5);
if(row >= TDISP_ROWS) write_cmd(0x06);
row = TDISP_ROWS - 1; chThdSleepMicroseconds(50);
tdisp_lld_write_cmd(0x80 | (col + row_offsets[row])); return TRUE;
} }
void tdisp_lld_create_char(uint8_t address, char *charmap) { void tdisp_lld_clear(void) {
uint8_t i; write_cmd(0x01);
}
/* make sure we don't write somewhere we're not supposed to */
address &= TDISP_MAX_CUSTOM_CHARS; void tdisp_lld_draw_char(char c) {
write_data(c);
tdisp_lld_write_cmd(0x40 | (address << 3)); }
for(i = 0; i < 8; i++) { void tdisp_lld_set_cursor(coord_t col, coord_t row) {
tdisp_lld_write_data(charmap[i]); static const uint8_t row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
}
} /*
* Short-cut:
void tdisp_lld_clear(void) { *
tdisp_lld_write_cmd(0x01); * If x and y = 0 then use the home command.
} *
* Note: There is probably no advantage as both commands are a single byte
void tdisp_lld_home(void) { */
tdisp_lld_write_cmd(0x02); // if (col == 0 && row == 0) {
} // write_cmd(0x02);
// return;
void tdisp_lld_control(uint16_t what, void *value) { // }
(void)what;
(void)value; write_cmd(0x80 | (col + row_offsets[row]));
/* }
switch(attributes) {
case TDISP_ON: void tdisp_lld_create_char(uint8_t address, uint8_t *charmap) {
_displaycontrol |= 0x04; int i;
tdisp_lld_write_cmd(0x08 | _displaycontrol);
break; write_cmd(0x40 | (address << 3));
case TDISP_OFF: for(i = 0; i < CUSTOM_CHAR_YBITS; i++)
_displaycontrol &=~ 0x04; write_data(charmap[i]);
tdisp_lld_write_cmd(0x08 | _displaycontrol); }
break;
case TDISP_CURSOR_ON: void tdisp_lld_control(uint16_t what, void *value) {
_displaycontrol |= 0x02; switch(what) {
tdisp_lld_write_cmd(0x08 | _displaycontrol); case TDISP_CTRL_BACKLIGHT:
break; if ((uint8_t)value)
case TDISP_CURSOR_OFF: displaycontrol |= DISPLAY_ON;
_displaycontrol &=~ 0x02; else
tdisp_lld_write_cmd(0x08 | _displaycontrol); displaycontrol &= ~DISPLAY_ON;
break; write_cmd(0x08 | displaycontrol);
case TDISP_CURSOR_BLINK_ON: break;
_displaycontrol |= 0x00; case TDISP_CTRL_CURSOR:
tdisp_lld_write_cmd(0x08 | _displaycontrol); switch((cursorshape)value) {
break; case cursorOff:
case TDISP_CURSOR_BLINK_OFF: displaycontrol &= ~CURSOR_ON;
_displaycontrol &=~ 0x00; break;
tdisp_lld_write_cmd(0x08 | _displaycontrol); case cursorBlock:
break; case cursorUnderline:
} case cursorBar:
*/ displaycontrol = (displaycontrol | CURSOR_ON) & ~CURSOR_BLINK;
} break;
case cursorBlinkingBlock:
#endif /* GFX_USE_TDISP */ case cursorBlinkingUnderline:
/** @} */ case cursorBlinkingBar:
default:
displaycontrol |= (CURSOR_ON | CURSOR_BLINK);
break;
}
write_cmd(0x08 | displaycontrol);
break;
}
}
#endif /* GFX_USE_TDISP */
/** @} */

View File

@ -1,64 +1,48 @@
/* /*
ChibiOS/GFX - Copyright (C) 2012 ChibiOS/GFX - Copyright (C) 2012
Joel Bodenmann aka Tectu <joel@unormal.org> Joel Bodenmann aka Tectu <joel@unormal.org>
This file is part of ChibiOS/GFX. This file is part of ChibiOS/GFX.
ChibiOS/GFX is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
ChibiOS/GFX is distributed in the hope that it will be useful, ChibiOS/GFX is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** /**
* @file drivers/tdisp/HD44780/tdisp_lld_board_example.h * @file drivers/tdisp/HD44780/tdisp_lld_board_example.h
* @brief TDISP driver subsystem board interface for the HD44780 display * @brief TDISP driver subsystem board interface for the HD44780 display
* *
* @addtogroup TDISP * @addtogroup TDISP
* @{ * @{
*/ */
#ifndef _TDISP_LLD_BOARD_H #ifndef _TDISP_LLD_BOARD_H
#define _TDISP_LLD_BOARD_H #define _TDISP_LLD_BOARD_H
void init_board(void) { static void init_board(void) {
palSetGroupMode(GPIOE, PAL_WHOLE_PORT, 0, PAL_MODE_OUTPUT_PUSHPULL); /* Code here */
palSetGroupMode(GPIOG, PAL_WHOLE_PORT, 0, PAL_MODE_OUTPUT_PUSHPULL); #error "tdispHD44780: You must supply a definition for init_board for your board"
} }
void setpin_e(bool_t state) { static void write_cmd(uint8_t data) {
if(state) /* Code here */
palSetPad(GPIOE, 2); #error "tdispHD44780: You must supply a definition for write_cmd for your board"
else }
palClearPad(GPIOE, 2);
} static void write_data(uint8_t data) {
/* Code here */
void setpin_rs(bool_t state) { #error "tdispHD44780: You must supply a definition for write_data for your board"
if(state) }
palSetPad(GPIOE, 0);
else #endif /* _TDISP_LLD_BOARD_H */
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);
}
#endif /* _TDISP_LLD_BOARD_H */
/** @} */

View 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 */
/** @} */

View File

@ -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 */
/** @} */

View File

@ -48,11 +48,8 @@
#define GDISP_INCLUDE_FONT_UI2 TRUE #define GDISP_INCLUDE_FONT_UI2 TRUE
#define GDISP_INCLUDE_FONT_LARGENUMBERS TRUE #define GDISP_INCLUDE_FONT_LARGENUMBERS TRUE
/* TDISP options */ /* Features for the TDISP subsystem. */
#define TDISP_COLUMNS 16 #define TDISP_NEED_MULTITHREAD FALSE
#define TDISP_ROWS 2
#define TDISP_NEED_4BIT_MODE FALSE
#define TDISP_NEED_8BIT_MODE FALSE
/* Features for the GWIN subsystem. */ /* Features for the GWIN subsystem. */
#define GWIN_NEED_BUTTON FALSE #define GWIN_NEED_BUTTON FALSE
@ -101,6 +98,8 @@
#define GDISP_USE_GPIO #define GDISP_USE_GPIO
#define GDISP_VMT_NAME1(x) x##YourDriver1 #define GDISP_VMT_NAME1(x) x##YourDriver1
#define GDISP_VMT_NAME2(x) x##YourDriver2 #define GDISP_VMT_NAME2(x) x##YourDriver2
#define TDISP_COLUMNS 16
#define TDISP_ROWS 2
*/ */
#endif /* _GFXCONF_H */ #endif /* _GFXCONF_H */

View File

@ -1,57 +1,53 @@
/* /*
ChibiOS/GFX - Copyright (C) 2012 ChibiOS/GFX - Copyright (C) 2012
Joel Bodenmann aka Tectu <joel@unormal.org> Joel Bodenmann aka Tectu <joel@unormal.org>
This file is part of ChibiOS/GFX. This file is part of ChibiOS/GFX.
ChibiOS/GFX is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
ChibiOS/GFX is distributed in the hope that it will be useful, ChibiOS/GFX is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** /**
* @file include/tdisp/lld/tdisp_lld.h * @file include/tdisp/lld/tdisp_lld.h
* @brief TDISP driver subsystem low level driver header. * @brief TDISP driver subsystem low level driver header.
* *
* @addtogroup TDISP * @addtogroup TDISP
* @{ * @{
*/ */
#ifndef _TDISP_LLD_H #ifndef _TDISP_LLD_H
#define _TDISP_LLD_H #define _TDISP_LLD_H
#if GFX_USE_TDISP || defined(__DOXYGEN__) #if GFX_USE_TDISP || defined(__DOXYGEN__)
#include "tdisp_lld_config.h" #ifdef __cplusplus
extern "C" {
#ifdef __cplusplus #endif
extern "C" {
#endif bool_t tdisp_lld_init(void);
void tdisp_lld_clear(void);
extern void tdisp_lld_write_cmd(uint8_t data); void tdisp_lld_draw_char(char c);
extern void tdisp_lld_write_data(uint8_t data); void tdisp_lld_set_cursor(coord_t col, coord_t row);
extern bool_t tdisp_lld_init(void); void tdisp_lld_create_char(uint8_t address, uint8_t *charmap);
extern void tdisp_lld_set_cursor(coord_t col, coord_t row); void tdisp_lld_control(uint16_t what, void *value);
extern void tdisp_lld_create_char(uint8_t address, char *charmap);
extern void tdisp_lld_clear(void); #ifdef __cplusplus
extern void tdisp_lld_home(void); }
extern void tdisp_lld_control(uint16_t what, void *value); #endif
#ifdef __cplusplus #endif /* GFX_USE_TDISP */
}
#endif #endif /* _TDISP_LLD_H */
/** @} */
#endif /* GFX_USE_TDISP */
#endif /* _TDISP_LLD_H */
/** @} */

View File

@ -31,53 +31,44 @@
#if GFX_USE_TDISP #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 #ifndef TDISP_NEED_MULTITHREAD
#define TDISP_NEED_4BIT_MODE FALSE #define TDISP_NEED_MULTITHREAD FALSE
#endif #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 #ifndef TDISP_USE_CUSTOM_BOARD
#define TDISP_NEED_8BIT_MODE FALSE #define TDISP_USE_CUSTOM_BOARD FALSE
#endif #endif
/**
#if (!TDISP_NEED_4BIT_MODE && !TDISP_NEED_8BIT_MODE) * @brief Set the screen height and width.
#error "Either TDISP_NEED_4BIT_MODE or TDISP_NEED_8BIT_MODE needs to be set to TRUE in your gfxconf.h!" * @note Ignored by some low level GDISP drivers, optional for others.
#endif * @note Where these values are allowed, a default is always provided by the low level driver.
*/
#if (TDISP_NEED_4BIT_MODE && TDISP_NEED_8BIT_MODE) /* #define TDISP_COLUMNS 16 */
#error "Only TDISP_NEED_4BIT_MODE or TDISP_NEED_8BIT_MODE can be set to TRUE, not both at one!" /* #define TDISP_ROWS 2 */
#endif
/** @} */ /** @} */
#endif /* GFX_USE_TDISP */ #endif /* GFX_USE_TDISP */

View File

@ -1,147 +1,206 @@
/* /*
ChibiOS/GFX - Copyright (C) 2012 ChibiOS/GFX - Copyright (C) 2012
Joel Bodenmann aka Tectu <joel@unormal.org> Joel Bodenmann aka Tectu <joel@unormal.org>
This file is part of ChibiOS/GFX. This file is part of ChibiOS/GFX.
ChibiOS/GFX is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
ChibiOS/GFX is distributed in the hope that it will be useful, ChibiOS/GFX is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** /**
* @file include/tdisp/tdisp.h * @file include/tdisp/tdisp.h
* @brief TDISP Graphic Driver subsystem header file. * @brief TDISP Graphic Driver subsystem header file.
* *
* @addtogroup TDISP * @addtogroup TDISP
* *
* @details The TDISP module provides high level abstraction to interface pixel oriented graphic displays. * @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. * 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 * @pre GFX_USE_TDISP must be set to TRUE in gfxconf.h
* *
* @{ * @{
*/ */
#ifndef _TDISP_H #ifndef _TDISP_H
#define _TDISP_H #define _TDISP_H
#include "gfx.h" #include "gfx.h"
#if GFX_USE_TDISP || defined(__DOXYGEN__) #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 {
* @name TDISP display attributes cursorOff,
* @{ cursorBlock,
*/ cursorBlinkingBlock,
#define TDISP_ON 0x01 cursorUnderline,
#define TDISP_OFF 0x02 cursorBlinkingUnderline,
#define TDISP_CURSOR_ON 0x03 cursorBar,
#define TDISP_CURSOR_OFF 0x04 cursorBlinkingBar,
#define TDISP_CURSOR_BLINK_ON 0x05 } cursorshape;
#define TDISP_CURSOR_BLINK_OFF 0x06
/** @} */ /**
* @name TDISP control values
/** * @note The low level driver may define extra control values
* @brief TDISP driver initialisation * @{
* @note This function is not implicitly invoked by @p halInit(). */
* It must be called manually. #define TDISP_CTRL_BACKLIGHT 0x0000
* #define TDISP_CTRL_CURSOR 0x0001
* @return TRUE if success, FALSE otherwise /** @} */
*
* @init /**
*/ * @brief The TDISP structure definition
bool_t tdispInit(void); */
typedef struct tdispStruct_t {
/** coord_t columns, rows;
* @brief Control different display properties coord_t charBitsX, charBitsY;
* @note A wrapper macro exists for each option, please use them uint16_t maxCustomChars;
* instead of this function manually. } tdispStruct;
*
* @param[in] what What you want to control /**
* @param[in] value The value to be assigned * @brief The TDISP structure
*/ */
void tdispControl(uint16_t what, void *value); extern tdispStruct TDISP;
/** #ifdef __cplusplus
* @brief Clears the display extern "C" {
*/ #endif
void tdispClear(void);
/**
/** * @brief TDISP driver initialisation
* @brief Sets the cursor to it's home position ( 0/0 ) * @note This function is not implicitly invoked by @p halInit().
*/ * It must be called manually.
void tdispHome(void); *
* @return TRUE if success, FALSE otherwise
/** *
* @brief Set cursor to a certain position * @init
* */
* @param[in] col The column bool_t tdispInit(void);
* @param[in] row The row
*/ /**
void tdispSetCursor(coord_t col, coord_t row); * @brief Clears the display
*/
/** void tdispClear(void);
* @brief Store a custom character in RAM
* /**
* @note This usually must be done after each power-up since most * @brief Sets the cursor to it's home position ( 0, 0 )
* LCDs lose their RAM content. */
* void tdispHome(void);
* @param[in] address On which address to store the character (from 0 up to max)
* @param[in] charmap The character to be stored. /**
*/ * @brief Set cursor to a specified position
void tdispCreateChar(uint8_t address, char *charmap); *
* @param[in] col The column (x)
/** * @param[in] row The row (y)
* @brief Draws a single character at the current cursor position */
* void tdispSetCursor(coord_t col, coord_t row);
* @param[in] c The character to be drawn
*/ /**
void tdispDrawChar(char c); * @brief Store a custom character into the display
*
/** * @note This usually must be done after each power-up since most
* @brief Draws a string at the current cursor position * LCDs lose their RAM content.
* *
* @param[in] s The string to be drawn * @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.
void tdispDrawString(char *s); *
* @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
* @brief Draws a single character at a given position * packed.
* @note This function manipulates the cursor position and it will not be */
* reset to it's original state void tdispCreateChar(uint8_t address, uint8_t *charmap);
*
* @param[in] col The column /**
* @param[in] row The row * @brief Draws a single character at the current cursor position and advances the cursor
* @param[in] c The character to be drawn *
*/ * @param[in] c The character to be drawn
void tdispDrawCharLocation(coord_t col, coord_t row, char c); *
* @note Writing past the end of a row leaves the cursor in an undefined position.
/** */
* @brief Draws a string at a given position void tdispDrawChar(char c);
* @note This function manipulates the cursor position and it will not be
* reset to it's original state /**
* * @brief Draws a string at the current cursor position and advances the cursor
* @param[in] col The column *
* @param[in] row The row * @param[in] s The string to be drawn
* @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
void tdispDrawStringLocation(coord_t col, coord_t row, char *s); * the next row. The cursor is also left in an undefined position.
*/
#endif /* GFX_USE_TDISP */ void tdispDrawString(char *s);
#endif /* _TDISP_H */ /**
/** @} */ * @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

@ -1,85 +1,117 @@
/* /*
ChibiOS/GFX - Copyright (C) 2012 ChibiOS/GFX - Copyright (C) 2012
Joel Bodenmann aka Tectu <joel@unormal.org> Joel Bodenmann aka Tectu <joel@unormal.org>
This file is part of ChibiOS/GFX. This file is part of ChibiOS/GFX.
ChibiOS/GFX is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
ChibiOS/GFX is distributed in the hope that it will be useful, ChibiOS/GFX is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** /**
* @file src/tdisp/tdisp.c * @file src/tdisp/tdisp.c
* @brief TDISP Driver code. * @brief TDISP Driver code.
* *
* @addtogroup TDISP * @addtogroup TDISP
* @{ * @{
*/ */
#include "ch.h" #include "ch.h"
#include "hal.h" #include "hal.h"
#include "gfx.h" #include "gfx.h"
#if GFX_USE_TDISP || defined(__DOXYGEN__) #if GFX_USE_TDISP || defined(__DOXYGEN__)
static uint8_t _displaycontrol; #include "tdisp/lld/tdisp_lld.h"
bool_t tdispInit(void) { #if TDISP_NEED_MULTITHREAD
bool_t ret; #if !CH_USE_MUTEXES
#error "TDISP: CH_USE_MUTEXES must be defined in chconf.h because TDISP_NEED_MULTITHREAD is defined"
ret = tdisp_lld_init(); #endif
return ret; static Mutex tdispMutex;
}
#define MUTEX_INIT() chMtxInit(&tdispMutex)
void tdispControl(uint16_t what, void *value) { #define MUTEX_ENTER() chMtxLock(&tdispMutex)
tdisp_lld_control(what, value); #define MUTEX_LEAVE() chMtxUnlock()
}
#else
void tdispClear(void) {
tdisp_lld_clear(); #define MUTEX_INIT()
} #define MUTEX_ENTER()
#define MUTEX_LEAVE()
void tdispHome(void) {
tdisp_lld_home(); #endif
}
bool_t tdispInit(void) {
void tdispCreateChar(uint8_t address, char *charmap) { bool_t res;
tdisp_lld_create_char(address, charmap);
} MUTEX_INIT();
void tdispSetCursor(coord_t col, coord_t row) { MUTEX_ENTER();
tdisp_lld_set_cursor(col, row); res = tdisp_lld_init();
} MUTEX_LEAVE();
void tdispDrawChar(char c) { return res;
tdisp_lld_write_data(c); }
}
void tdispClear(void) {
void tdispDrawString(char *s) { MUTEX_ENTER();
while(*s) tdisp_lld_clear();
tdispDrawChar(*s++); MUTEX_LEAVE();
} }
void tdispDrawCharLocation(coord_t col, coord_t row, char c) { void tdispHome(void) {
tdispSetCursor(col, row); MUTEX_ENTER();
tdispDrawChar(c); tdisp_lld_set_cursor(0, 0);
} MUTEX_LEAVE();
}
void tdispDrawStringLocation(coord_t col, coord_t row, char *s) {
tdispSetCursor(col, row); void tdispSetCursor(coord_t col, coord_t row) {
tdispDrawString(s); /* Keep the input range valid */
} if (row >= TDISP.rows)
row = TDISP.rows - 1;
#endif /* GFX_USE_TDISP */ 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 */
/** @} */