Skip to content

Instantly share code, notes, and snippets.

@abhishek-kakkar
Created October 24, 2012 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhishek-kakkar/aa6a7c45a94143762277 to your computer and use it in GitHub Desktop.
Save abhishek-kakkar/aa6a7c45a94143762277 to your computer and use it in GitHub Desktop.
I8080 System GPIO interface driver
/*
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/>.
*/
#include "halconf.h"
#if defined(GDISP_USE_GPIO)
#define Set_CS palSetPad(GDISP_CMD_PORT, GDISP_CS_PAD);
#define Clr_CS palClearPad(GDISP_CMD_PORT, GDISP_CS_PAD);
#define Set_RS palSetPad(GDISP_CMD_PORT, GDISP_RS_PAD);
#define Clr_RS palClearPad(GDISP_CMD_PORT, GDISP_RS_PAD);
#define Set_WR palSetPad(GDISP_CMD_PORT, GDISP_WR_PAD);
#define Clr_WR palClearPad(GDISP_CMD_PORT, GDISP_WR_PAD);
#define Set_RD palSetPad(GDISP_CMD_PORT, GDISP_RD_PAD);
#define Clr_RD palClearPad(GDISP_CMD_PORT, GDISP_RD_PAD);
extern void i80_write_gpio(uint16_t data);
extern uint16_t i80_read_gpio(void);
extern void i80_gpio_set_direction(bool_t dir);
/* Place all the GPIO pins in a known state.
* Note that this does not affect any GPIO configuration,
* which needs to be set beforehand, preferably in board.h
*/
__inline void i80_interface_init(void) {
Set_CS;
Set_RS;
Set_WR;
Set_RD;
}
__inline void i80_interface_delay(void) {
#if defined(STM32F1XX)
/* No delay required */
#elif defined(STM32F4XX)
/* 2xHCLK delay required to work */
asm volatile ("nop");
asm volatile ("nop");
#endif
}
__inline void i80_lcd_write_index(uint16_t index) {
Clr_RS;
i80_write_gpio(index);
Clr_WR;
i80_interface_delay();
Set_WR;
Set_RS;
}
__inline void i80_lcd_write_data(uint16_t data) {
i80_write_gpio_lld(data);
Clr_WR;
i80_interface_delay();
Set_WR;
}
__inline uint16_t i80_lcd_read(void) {
uint16_t value;
Clr_RD;
i80_interface_delay();
value = i80_read_gpio();
Set_RD;
return value;
}
__inline void i80_lcd_write_reg(uint16_t lcdReg,uint16_t lcdRegValue) {
Clr_CS;
i80_lcd_write_index(lcdReg);
i80_lcd_write_data(lcdRegValue);
Set_CS;
}
__inline uint16_t i80_lcd_read_reg(uint16_t lcdReg) {
uint16_t value;
Clr_CS;
i80_lcd_write_index(lcdReg);
i80_gpio_set_direction(1);
value = i80_lcd_read();
i80_gpio_set_direction(0);
Set_CS;
return value;
}
__inline void i80_lcd_burst_write_start(uint16_t writeIndex) {
Clr_CS;
i80_lcd_write_index(writeIndex);
}
__inline void i80_lcd_burst_write_stop(void) {
Set_CS;
}
__inline void i80_lcd_burst_write(uint16_t *buffer, uint16_t size) {
while (size-- != 0) {
i80_write_gpio(data);
Clr_WR;
i80_interface_delay();
Set_WR;
}
}
__inline void i80_lcd_burst_read_start(uint16_t readIndex) {
Clr_CS;
i80_lcd_write_index(readIndex);
i80_gpio_set_direction(1); /* Configure data pads for input */
}
__inline void i80_lcd_burst_read_stop(void) {
Set_CS;
i80_gpio_set_direction(0); /* Configure data pads for output */
}
__inline void i80_lcd_burst_read(uint16_t *buffer, size_t size) {
volatile uint16_t dummy;
dummy = i80_lcd_read(); /* Dummy read */
while (size-- != 0)
*buffer++ = i80_lcd_read();
(void)dummy; /* Keep the compiler happy */
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment