Subversion Repositories libSSD1306

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #include "ch.h"
  2. #include "hal.h"
  3.  
  4. #include "spiInterface.h"
  5.  
  6. void ssd1306spiInit(void) {
  7. static const    SPIConfig spiConfig = {
  8.                         .ssport = SPI_CS_GPIO,
  9.                         .sspad = SPI_CS_PIN,
  10.                         .cr1 = SPI_CR1_MSTR
  11.                          | SPI_CR1_CPOL
  12.                      | SPI_CR1_CPHA
  13.                          | SPI_BaudRatePrescaler_4
  14.         };
  15.  
  16.         spiStart(&SPID1, &spiConfig);
  17. }
  18.  
  19. void ssd1306fastSPIwrite(uint8_t c) {
  20. //      char c = d;
  21.         pal_lld_setport(SPI_CD_GPIO, 1 << SPI_CD_PIN);
  22.         spiSelect(&SPID1);
  23.         spiSend(&SPID1, 1, &c);
  24.         spiUnselect(&SPID1);
  25. }
  26.  
  27. void ssd1306commandSPIwrite(uint8_t c) {
  28. //      char c = d;
  29.         pal_lld_clearport(SPI_CD_GPIO, 1 << SPI_CD_PIN);
  30.         spiSelect(&SPID1);
  31.         spiSend(&SPID1, 1, &c);
  32.         spiUnselect(&SPID1);
  33. }
  34.  
  35. void ssd1306resetDisplay(void) {
  36.  
  37.         pal_lld_setport(SPI_RESET_GPIO, 1 << SPI_RESET_PIN);
  38. // VDD (3.3V) goes high at start, lets just chill for a ms
  39.         chThdSleep(1);
  40. // bring reset low
  41.         pal_lld_clearport(SPI_RESET_GPIO, 1 << SPI_RESET_PIN);
  42.         /// wait 10ms
  43.         chThdSleep(1);
  44. // bring out of reset
  45.         pal_lld_setport(SPI_RESET_GPIO, 1 << SPI_RESET_PIN);
  46.         /// turn on VCC (9V?)
  47. // set CD pin
  48.         pal_lld_setport(SPI_CD_GPIO, 1 << SPI_CD_PIN);
  49. }
  50.  
  51. void ssd1306SendDisplay(uint8_t * buffer, uint8_t len) {
  52.         pal_lld_setport(SPI_CD_GPIO, 1 << SPI_CD_PIN);
  53.         spiSelect(&SPID1);
  54.         spiSend(&SPID1, len, buffer);
  55.         spiUnselect(&SPID1);
  56.  
  57. }
  58.  
  59.