diff options
author | Daniel Friesel <derf@finalrewind.org> | 2018-01-11 14:23:07 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2018-01-11 14:23:07 +0100 |
commit | 0d84f5e512c4148bc45dd26eea177e09c0a21b56 (patch) | |
tree | 8d8ae62a68f11482d1c25f32d86cf1c43246f61d /src/driver/sharp96.cc | |
parent | 1978e406b816d463dc7feab083ce30638e8b787a (diff) |
Add Sharp96 display driver, split up msp430 SPI into a1 / b
Diffstat (limited to 'src/driver/sharp96.cc')
-rw-r--r-- | src/driver/sharp96.cc | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/driver/sharp96.cc b/src/driver/sharp96.cc new file mode 100644 index 0000000..1e9a2ec --- /dev/null +++ b/src/driver/sharp96.cc @@ -0,0 +1,80 @@ +#include "driver/sharp96.h" +#include "driver/spi_b.h" +#include "driver/gpio.h" + +#ifndef SHARP96_POWER_PIN +#error makeflag sharp96_power_pin required +#endif + +#ifndef SHARP96_EN_PIN +#error makeflag sharp96_en_pin required +#endif + +#ifndef SHARP96_CS_PIN +#error makeflag sharp96_cs_pin required +#endif + +#define CMD_WRITE_LINE 0x80 +#define CMD_TOGGLE_VCOM 0x40 +#define CMD_CLEAR_SCREEN 0x20 + +void Sharp96::setup() +{ + gpio.output(SHARP96_POWER_PIN); + gpio.output(SHARP96_EN_PIN); + gpio.output(SHARP96_CS_PIN); +} + +void Sharp96::powerOn() +{ + gpio.write(SHARP96_POWER_PIN, 1); + gpio.write(SHARP96_EN_PIN, 1); +} + +void Sharp96::powerOff() +{ + gpio.write(SHARP96_EN_PIN, 0); + gpio.write(SHARP96_POWER_PIN, 0); +} + +unsigned char Sharp96::swap_bits(unsigned char byte) +{ + byte = (byte & 0xF0) >> 4 | (byte & 0x0F) << 4; + byte = (byte & 0xCC) >> 2 | (byte & 0x33) << 2; + byte = (byte & 0xAA) >> 1 | (byte & 0x55) << 1; + return byte; +} + +void Sharp96::clear() +{ + gpio.write(SHARP96_CS_PIN, 1); + txbuf[0] = CMD_CLEAR_SCREEN | (CMD_TOGGLE_VCOM * vcom); + txbuf[1] = 0; + spi.xmit(2, txbuf, 0, txbuf); + gpio.write(SHARP96_CS_PIN, 0); +} + +void Sharp96::writeLine(unsigned char line_no, unsigned char* data) +{ + txbuf[0] = CMD_WRITE_LINE | (CMD_WRITE_LINE * vcom); + txbuf[1] = swap_bits(line_no + 1); + gpio.write(SHARP96_CS_PIN, 1); + spi.xmit(2, txbuf, 0, txbuf); + spi.xmit(12, data, 0, txbuf); + txbuf[0] = 0; + txbuf[1] = 0; + spi.xmit(2, txbuf, 0, txbuf); + gpio.write(SHARP96_CS_PIN, 0); +} + +void Sharp96::toggleVCOM() +{ + vcom = !vcom; + txbuf[0] = CMD_TOGGLE_VCOM * vcom; + txbuf[1] = 0; + gpio.write(SHARP96_CS_PIN, 1); + spi.xmit(2, txbuf, 0, txbuf); + gpio.write(SHARP96_CS_PIN, 0); +} + +Sharp96 sharp96; |