Permalink
Browse files

- added ST7735D/R to LCD protocol

  • Loading branch information...
smdprutser committed Apr 18, 2018
1 parent 234f8c1 commit 986c1611ea8c3c59cafdfcfd9d9f4940cca6962b
Showing with 622 additions and 143 deletions.
  1. +199 −0 source/HD44780.c
  2. +12 −0 source/HD44780.h
  3. +44 −136 source/LCDSPI.c
  4. +0 −6 source/LCDSPI.h
  5. +1 −1 source/Makefile
  6. +309 −0 source/ST7735R.c
  7. +57 −0 source/ST7735R.h
@@ -0,0 +1,199 @@
#include <stdint.h>
#include <libopencm3/stm32/spi.h>
#include "buspirateNG.h"
#include "HWSPI.h"
#include "cdcacm.h"
#include "UI.h"
#include "LCDSPI.h"
#include "HD44780.h"
static void HD44780_send(uint8_t rs, uint8_t d);
// hd44780 driver
#define HCT595_LCD_LED 0b00000001
#define HCT595_LCD_RS 0b00000010
#define HCT595_LCD_RW 0b00000100
#define HCT595_LCD_EN 0b00001000
#define HCT595_LCD_D4 0b00010000
#define HCT595_LCD_D5 0b00100000
#define HCT595_LCD_D6 0b01000000
#define HCT595_LCD_D7 0b10000000
#define CMD_CLEARDISPLAY 0b00000001 //82us-1.64ms
#define CMD_RETURNHOME 0b00000010 //40us-1.64ms
#define CMD_ENTRYMODESET 0b00000100 //40us
#define INCREMENT 0b10
#define DECREMENT 0b00
#define DISPLAYSHIFTON 0b1
#define DISPLAYSHIFTOFF 0
#define CMD_DISPLAYCONTROL 0b00001000 //40us
#define DISPLAYON 0b100
#define DISPLAYOFF 0
#define CURSERON 0b10
#define CURSEROFF 0
//#define BLINKON 0b1
//#define BLINKOFF 0
#define CMD_CURSERDISPLAYSHIFT 0b00010000 //40us
#define DISPLAYSHIFT 0b1000
#define CURSERMOVE 0
#define SHIFTRIGHT 0b100
#define SHIFTLEFT 0
#define CMD_FUNCTIONSET 0b00100000 //40us
#define DATAWIDTH8 0b10000
#define DATAWIDTH4 0
#define DISPLAYLINES2 0b1000
#define DISPLAYLINES1 0
#define FONT5X10 0b100
#define FONT5X7 0
#define MODULE24X4 0b1
#define CMD_SETCGRAMADDR 0b01000000 //40us
//6bit character generator RAM address
#define CMD_SETDDRAMADDR 0b10000000 //40us
//7bit display data RAM address
uint32_t HD44780_write(uint32_t d)
{
HD44780_send(1, d&0xff);
return 0;
}
uint32_t HD44780_read(void)
{
return 0;
}
void HD44780_macro(uint32_t macro)
{
uint32_t arg1;
uint32_t i;
cmdtail=(cmdtail+1)&(CMDBUFFSIZE-1);
consumewhitechars();
arg1=getint();
cdcprintf("arg=%d", arg1);
switch(macro)
{
case 0: cdcprintf(" 1. reset and init 1 line\r\n");
cdcprintf(" 2. reset and init 2 lines\r\n");
cdcprintf(" 3. clear display\r\n");
cdcprintf(" 4. set cursor\r\n");
cdcprintf(" 5. write command n\r\n");
cdcprintf(" 6. write n digits to display\r\n");
cdcprintf(" 7. write n chars to display\r\n");
break;
case 1:
case 2: HD44780_reset();
HD44780_init(macro);
break;
case 3: HD44780_send(0, CMD_CLEARDISPLAY);
break;
case 4: arg1&=0x7f;
HD44780_send(0, CMD_SETDDRAMADDR|arg1);
break;
case 5: HD44780_send(1, arg1);
break;
case 6: for(i=0; i<arg1; i++)
HD44780_send(1, 0x30+(i%10));
break;
case 7: for(i=0; i<arg1; i++)
HD44780_send(1, 0x20+(i%0x5e));
break;
default: cdcprintf("Macro not defined");
modeConfig.error=1;
}
}
void HD44780_setup(void)
{
// setup SPI
HWSPI_setcpol(1<<1);
HWSPI_setcpha(1);
HWSPI_setbr(5<<3);
HWSPI_setdff(SPI_CR1_DFF_8BIT);
HWSPI_setlsbfirst(SPI_CR1_MSBFIRST);
HWSPI_setcsidle(1);
HWSPI_setup_exc();
cdcprintf("This mode uses an external adapter");
}
void HD44780_cleanup(void)
{
HWSPI_cleanup();
}
void HD44780_reset(void)
{
HWSPI_xfer(0x00);
HWSPI_setcs(1);
HWSPI_setcs(0);
delayms(15);
HD44780_writenibble(0, 0x03);
delayms(15);
HD44780_writenibble(0, 0x03);
delayms(15);
HD44780_writenibble(0, 0x03);
delayms(15);
HD44780_writenibble(0, 0x02);
delayms(15);
}
void HD44780_init(uint8_t lines)
{
if(lines==1)
HD44780_send(0, 0x20);
else
HD44780_send(0, 0x28);
delayms(15);
HD44780_send(0, 0x08);
delayms(15);
HD44780_send(0, 0x01);
delayms(15);
HD44780_send(0, 0x0f);
delayms(15);
}
static void HD44780_send(uint8_t rs, uint8_t d)
{
HD44780_writenibble(rs, (d>>4));
HD44780_writenibble(rs, (d&0x0F));
}
void HD44780_writenibble(uint8_t rs, uint8_t d)
{
d&=0x0F;
d<<=4;
d|=HCT595_LCD_LED;
if(rs) d|=HCT595_LCD_RS;
HWSPI_xfer(d);
HWSPI_setcs(1);
HWSPI_setcs(0);
HWSPI_xfer(d|HCT595_LCD_EN);
HWSPI_setcs(1);
HWSPI_setcs(0);
HWSPI_xfer(d);
HWSPI_setcs(1);
HWSPI_setcs(0);
}
@@ -0,0 +1,12 @@
void HD44780_setup(void);
void HD44780_cleanup(void);
uint32_t HD44780_write(uint32_t d);
uint32_t HD44780_read(void);
void HD44780_writenibble(uint8_t rs, uint8_t d);
void HD44780_init(uint8_t lines);
void HD44780_reset(void);
void HD44780_macro(uint32_t macro);
Oops, something went wrong.

0 comments on commit 986c161

Please sign in to comment.