Display: introduce displaybus.h.

This is a broker for mapping display bus calls to the bus actually
in use.
This commit is contained in:
Markus Hitter 2016-04-18 20:44:51 +02:00
parent 8c110da610
commit a97ec8a376
4 changed files with 78 additions and 26 deletions

51
displaybus.h Normal file
View File

@ -0,0 +1,51 @@
/** \file
\brief Display bus broker.
Here we map generic calls to the display bus to calls to the actually used
bus.
*/
#ifndef _DISPLAYBUS_H
#define _DISPLAYBUS_H
#include "config_wrapper.h"
#if defined DISPLAY_BUS_4BIT
#error Display connected directly via 4 pins is not yet supported.
#elif defined DISPLAY_BUS_8BIT
#error Display connected directly via 8 pins is not yet supported.
#elif defined DISPLAY_BUS_I2C
#include "i2c.h"
static void displaybus_init(uint8_t address) __attribute__ ((always_inline));
inline void displaybus_init(uint8_t address) {
return i2c_init(address);
}
static uint8_t displaybus_busy(void) __attribute__ ((always_inline));
inline uint8_t displaybus_busy(void) {
return i2c_busy();
}
static void displaybus_write(uint8_t data, uint8_t last_byte) \
__attribute__ ((always_inline));
inline void displaybus_write(uint8_t data, uint8_t last_byte) {
return i2c_write(data, last_byte);
}
#define DISPLAY_BUS
#elif defined DISPLAY_BUS_SPI
#error Display connected via SPI not yet supported.
#endif
#endif /* _DISPLAYBUS_H */

View File

@ -15,7 +15,7 @@
#include <string.h>
#include "config_wrapper.h"
#include "i2c.h"
#include "displaybus.h"
#define DISPLAY_I2C_ADDRESS (0x3C << 1)
@ -162,7 +162,8 @@ static void i2c_test(void) {
for (i = 0; i < sizeof(display_init); i++) {
// Send last byte with 'last_byte' set.
i2c_write(pgm_read_byte(&display_init[i]), (i == sizeof(display_init) - 1));
displaybus_write(pgm_read_byte(&display_init[i]),
(i == sizeof(display_init) - 1));
}
/**
@ -171,20 +172,20 @@ static void i2c_test(void) {
zeros, byte by byte.
*/
// Set horizontal adressing mode.
i2c_write(0x00, 0);
i2c_write(0x20, 0);
i2c_write(0x00, 1);
displaybus_write(0x00, 0);
displaybus_write(0x20, 0);
displaybus_write(0x00, 1);
// Write 512 zeros.
i2c_write(0x40, 0);
displaybus_write(0x40, 0);
for (i = 0; i < 512; i++) {
i2c_write(0x00, (i == 511));
displaybus_write(0x00, (i == 511));
}
// Return to page adressing mode.
i2c_write(0x00, 0);
i2c_write(0x20, 0);
i2c_write(0x02, 1);
displaybus_write(0x00, 0);
displaybus_write(0x20, 0);
displaybus_write(0x02, 1);
/**
Setup cursor on display.
@ -192,31 +193,31 @@ static void i2c_test(void) {
"Welcome to Teacup" is 64 pixel columns wide, entire display is
128 columns, so we offset by 32 columns to get it to the center.
*/
i2c_write(0x00, 0);
displaybus_write(0x00, 0);
// Line 1.
i2c_write(0xB0 | 1, 0);
displaybus_write(0xB0 | 1, 0);
// Column 32.
i2c_write(0x00 | (32 & 0x0F), 0);
i2c_write(0x10 | ((32 >> 4) & 0x0F), 1);
displaybus_write(0x00 | (32 & 0x0F), 0);
displaybus_write(0x10 | ((32 >> 4) & 0x0F), 1);
// Render text to bitmap to display.
i2c_write(0x40, 0);
displaybus_write(0x40, 0);
while (*message) {
uint8_t index = (uint8_t)*message - 0x20;
// Send the character bitmap.
for (i = 0; i < pgm_read_byte(&font_8x4[index].columns); i++) {
i2c_write(pgm_read_byte(&font_8x4[index].data[i]), 0);
displaybus_write(pgm_read_byte(&font_8x4[index].data[i]), 0);
}
// Send space between characters.
for (i = 0; i < FONT_SYMBOLS_SPACE; i++) {
i2c_write(0x00, 0);
displaybus_write(0x00, 0);
}
message++;
}
// Send another space for transmission end.
i2c_write(0x00, 1);
displaybus_write(0x00, 1);
}
#endif /* I2C_TEST */

View File

@ -51,7 +51,7 @@
#include "clock.h"
#include "intercom.h"
#include "spi.h"
#include "i2c.h"
#include "displaybus.h"
#include "sd.h"
#include "simulator.h"
@ -95,8 +95,8 @@ void init(void) {
spi_init();
#endif
#ifdef I2C
i2c_init(DISPLAY_I2C_ADDRESS);
#ifdef DISPLAY_BUS
displaybus_init(DISPLAY_I2C_ADDRESS);
#endif
// set up timers
@ -147,7 +147,7 @@ int main (void)
init();
#ifdef I2C
#ifdef DISPLAY_BUS
// This is temporary, until display code is completed.
i2c_test();
#endif

View File

@ -682,10 +682,10 @@ PWM value for 'off'
Comment in the one in use, comment out all others. If there is no display,
comment out all of them to remove display code for better performance.
*/
#define DISPLAY_BUS_4BIT
#define DISPLAY_BUS_8BIT
#define DISPLAY_BUS_I2C
#define DISPLAY_BUS_SPI
//#define DISPLAY_BUS_4BIT
//#define DISPLAY_BUS_8BIT
//#define DISPLAY_BUS_I2C
//#define DISPLAY_BUS_SPI
/** \def DISPLAY_TYPE_SSD1306 DISPLAY_TYPE_LCD1302