Port of the Adafruit PCD8544 Driver @ https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library for use in MBED Inital version only supports hardware SPI, and has been tested on a Nucleo test board. BSD license
Adafruit_PCD8544.h
00001 /********************************************************************* 00002 This is a library for our Monochrome Nokia 5110 LCD Displays 00003 00004 Pick one up today in the adafruit shop! 00005 ------> http://www.adafruit.com/products/338 00006 00007 These displays use SPI to communicate, 4 or 5 pins are required to 00008 interface 00009 00010 Adafruit invests time and resources providing this open source code, 00011 please support Adafruit and open-source hardware by purchasing 00012 products from Adafruit! 00013 00014 Written by Limor Fried/Ladyada for Adafruit Industries. 00015 BSD license, check license.txt for more information 00016 All text above, and the splash screen must be included in any redistribution 00017 00018 Modified for MBED usage and tested with STM32F411RE on a Nucleo board. 00019 Hardware SPI only, tested using default arduino pin out D11/D13 for MOSI/SCLK, Support provided for different pin layouts 00020 by James Kidd 2014 00021 *********************************************************************/ 00022 #include <stdint.h> 00023 #include <stdbool.h> 00024 #include "Adafruit_GFX.h" 00025 #include "mbed.h" 00026 #ifndef _ADAFRUIT_PCD8544_H 00027 #define _ADAFRUIT_PCD8544_H 00028 00029 #define LCD_SPI_MODE 0x01 00030 #define LCD_SPI_BITS 0x08 00031 00032 // Default to max SPI clock speed for PCD8544 of 4 mhz (16mhz / 4) for normal Arduinos. 00033 // This can be modified to change the clock speed if necessary (like for supporting other hardware). 00034 #define LCD_FREQ 400000 00035 #define PIN_RST 0x00 00036 #define PIN_SCE 0x01 00037 #define PIN_DC 0x02 00038 struct AdaLcdPins 00039 { 00040 PinName mosi; 00041 PinName miso; 00042 PinName sclk; 00043 PinName dc; 00044 PinName sce; 00045 PinName rst; 00046 }; 00047 00048 #define BLACK 1 00049 #define WHITE 0 00050 00051 00052 #define LCDWIDTH 84 00053 #define LCDHEIGHT 48 00054 00055 #define PCD8544_POWERDOWN 0x04 00056 #define PCD8544_ENTRYMODE 0x02 00057 #define PCD8544_EXTENDEDINSTRUCTION 0x01 00058 00059 #define PCD8544_DISPLAYBLANK 0x0 00060 #define PCD8544_DISPLAYNORMAL 0x4 00061 #define PCD8544_DISPLAYALLON 0x1 00062 #define PCD8544_DISPLAYINVERTED 0x5 00063 00064 // H = 0 00065 #define PCD8544_FUNCTIONSET 0x20 00066 #define PCD8544_DISPLAYCONTROL 0x08 00067 #define PCD8544_SETYADDR 0x40 00068 #define PCD8544_SETXADDR 0x80 00069 00070 // H = 1 00071 #define PCD8544_SETTEMP 0x04 00072 #define PCD8544_SETBIAS 0x10 00073 #define PCD8544_SETVOP 0x80 00074 00075 // Default to max SPI clock speed for PCD8544 of 4 mhz (16mhz / 4) for normal Arduinos. 00076 // This can be modified to change the clock speed if necessary (like for supporting other hardware). 00077 //#define PCD8544_SPI_CLOCK_DIV SPI_CLOCK_DIV4 00078 00079 class Adafruit_PCD8544 : public Adafruit_GFX { 00080 public: 00081 // Hardware SPI based on hardware controlled SCK (SCLK)13 and MOSI (DIN)11 pins. CS is still controlled by any IO pin. 00082 // NOTE: MISO and SS will be set as an input and output respectively, so be careful sharing those pins! 00083 Adafruit_PCD8544(PinName DC, PinName CS, PinName RST); 00084 //Untested choose clk/mosi pins 00085 Adafruit_PCD8544(PinName DC, PinName CS, PinName RST,PinName MOSI,PinName SCLK); 00086 00087 void begin(uint8_t contrast = 40, uint8_t bias = 0x04); 00088 00089 void command(uint8_t c); 00090 void data(uint8_t c); 00091 00092 void setContrast(uint8_t val); 00093 void clearDisplay(void); 00094 void display(); 00095 00096 void drawPixel(int16_t x, int16_t y, uint16_t color); 00097 uint8_t getPixel(int8_t x, int8_t y); 00098 00099 private: 00100 AdaLcdPins myPins; 00101 int8_t _din, _sclk, _dc, _rst, _cs; 00102 volatile uint8_t *mosiport, *clkport; 00103 uint8_t mosipinmask, clkpinmask; 00104 00105 SPI* LcdSPI; 00106 DigitalOut** Pins; 00107 void spiWrite(uint8_t c); 00108 bool isHardwareSPI(); 00109 }; 00110 00111 #endif
Generated on Tue Jul 26 2022 01:34:34 by 1.7.2