collab/PineapplePad

git clone https://git.julia.blue/collab/PineapplePad

Joseph RyanStart swapping sd streaming with midi generated audio6c1d72d

master
16.8 KiB427 linesraw
1/***************************************************
2  This is a library for the Adafruit 1.8" SPI display.
3  This library works with the Adafruit 1.8" TFT Breakout w/SD card
4  ----> http://www.adafruit.com/products/358
5  as well as Adafruit raw 1.8" TFT display
6  ----> http://www.adafruit.com/products/618
7
8  Check out the links above for our tutorials and wiring diagrams
9  These displays use SPI to communicate, 4 or 5 pins are required to
10  interface (RST is optional)
11  Adafruit invests time and resources providing this open source code,
12  please support Adafruit and open-source hardware by purchasing
13  products from Adafruit!
14
15  Written by Limor Fried/Ladyada for Adafruit Industries.
16  MIT license, all text above must be included in any redistribution
17 ****************************************************/
18
19// ST7735.h
20// Runs on LM4F120/TM4C123
21// Low level drivers for the ST7735 160x128 LCD based off of
22// the file described above.
23//    16-bit color, 128 wide by 160 high LCD
24// Daniel Valvano,
25// March 5, 2018
26// Augmented 7/17/2014 to have a simple graphics facility
27// Tested with LaunchPadDLL.dll simulator 9/2/2014
28
29/* This example accompanies the book
30   "Embedded Systems: Real Time Interfacing to Arm Cortex M Microcontrollers",
31   ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2017
32
33 Copyright 2018 by Jonathan W. Valvano, valvano@mail.utexas.edu
34    You may use, edit, run or distribute this file
35    as long as the above copyright notice remains
36 THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
37 OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
38 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
39 VALVANO SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
40 OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
41 For more information about my classes, my research, and my books, see
42 http://users.ece.utexas.edu/~valvano/
43 */
44
45// Backlight (pin 10) connected to +3.3 V
46// MISO (pin 9) unconnected
47// SCK (pin 8) connected to PA2 (SSI0Clk)
48// MOSI (pin 7) connected to PA5 (SSI0Tx)
49// TFT_CS (pin 6) connected to PA3 (SSI0Fss)
50// CARD_CS (pin 5) unconnected
51// Data/Command (pin 4) connected to PA6 (GPIO), high for data, low for command
52// RESET (pin 3) connected to PA7 (GPIO)
53// VCC (pin 2) connected to +3.3 V
54// Gnd (pin 1) connected to ground
55
56#ifndef _ST7735H_
57#define _ST7735H_
58#include <stdint.h>
59
60// some flags for ST7735_InitR()
61enum initRFlags{
62  none,
63  INITR_GREENTAB,
64  INITR_REDTAB,
65  INITR_BLACKTAB
66};
67
68#define ST7735_TFTWIDTH  128
69#define ST7735_TFTHEIGHT 160
70
71
72// Color definitions
73#define ST7735_BLACK   0x0000
74#define ST7735_BLUE    0xF800
75#define ST7735_RED     0x001F
76#define ST7735_GREEN   0x07E0
77#define ST7735_CYAN    0xFFE0
78#define ST7735_MAGENTA 0xF81F
79#define ST7735_YELLOW  0x07FF
80#define ST7735_WHITE   0xFFFF
81
82//------------ST7735_InitB------------
83// Initialization for ST7735B screens.
84// Input: none
85// Output: none
86void ST7735_InitB(void);
87
88
89//------------ST7735_InitR------------
90// Initialization for ST7735R screens (green or red tabs).
91// Input: option one of the enumerated options depending on tabs
92// Output: none
93void ST7735_InitR(enum initRFlags option);
94
95
96//------------ST7735_DrawPixel------------
97// Color the pixel at the given coordinates with the given color.
98// Requires 13 bytes of transmission
99// Input: x     horizontal position of the pixel, columns from the left edge
100//               must be less than 128
101//               0 is on the left, 126 is near the right
102//        y     vertical position of the pixel, rows from the top edge
103//               must be less than 160
104//               159 is near the wires, 0 is the side opposite the wires
105//        color 16-bit color, which can be produced by ST7735_Color565()
106// Output: none
107void ST7735_DrawPixel(int16_t x, int16_t y, uint16_t color);
108
109//------------ST7735_DrawFastVLine------------
110// Draw a vertical line at the given coordinates with the given height and color.
111// A vertical line is parallel to the longer side of the rectangular display
112// Requires (11 + 2*h) bytes of transmission (assuming image fully on screen)
113// Input: x     horizontal position of the start of the line, columns from the left edge
114//        y     vertical position of the start of the line, rows from the top edge
115//        h     vertical height of the line
116//        color 16-bit color, which can be produced by ST7735_Color565()
117// Output: none
118void ST7735_DrawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
119
120
121//------------ST7735_DrawFastHLine------------
122// Draw a horizontal line at the given coordinates with the given width and color.
123// A horizontal line is parallel to the shorter side of the rectangular display
124// Requires (11 + 2*w) bytes of transmission (assuming image fully on screen)
125// Input: x     horizontal position of the start of the line, columns from the left edge
126//        y     vertical position of the start of the line, rows from the top edge
127//        w     horizontal width of the line
128//        color 16-bit color, which can be produced by ST7735_Color565()
129// Output: none
130void ST7735_DrawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
131
132
133//------------ST7735_FillScreen------------
134// Fill the screen with the given color.
135// Requires 40,971 bytes of transmission
136// Input: color 16-bit color, which can be produced by ST7735_Color565()
137// Output: none
138void ST7735_FillScreen(uint16_t color);
139
140
141//------------ST7735_FillRect------------
142// Draw a filled rectangle at the given coordinates with the given width, height, and color.
143// Requires (11 + 2*w*h) bytes of transmission (assuming image fully on screen)
144// Input: x     horizontal position of the top left corner of the rectangle, columns from the left edge
145//        y     vertical position of the top left corner of the rectangle, rows from the top edge
146//        w     horizontal width of the rectangle
147//        h     vertical height of the rectangle
148//        color 16-bit color, which can be produced by ST7735_Color565()
149// Output: none
150void ST7735_FillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
151
152
153//------------ST7735_Color565------------
154// Pass 8-bit (each) R,G,B and get back 16-bit packed color.
155// Input: r red value
156//        g green value
157//        b blue value
158// Output: 16-bit color
159uint16_t ST7735_Color565(uint8_t r, uint8_t g, uint8_t b);
160
161//------------ST7735_SwapColor------------
162// Swaps the red and blue values of the given 16-bit packed color;
163// green is unchanged.
164// Input: x 16-bit color in format B, G, R
165// Output: 16-bit color in format R, G, B
166uint16_t ST7735_SwapColor(uint16_t x) ;
167
168
169//------------ST7735_DrawBitmap------------
170// Displays a 16-bit color BMP image.  A bitmap file that is created
171// by a PC image processing program has a header and may be padded
172// with dummy columns so the data have four byte alignment.  This
173// function assumes that all of that has been stripped out, and the
174// array image[] has one 16-bit halfword for each pixel to be
175// displayed on the screen (encoded in reverse order, which is
176// standard for bitmap files).  An array can be created in this
177// format from a 24-bit-per-pixel .bmp file using the associated
178// converter program.
179// (x,y) is the screen location of the lower left corner of BMP image
180// Requires (11 + 2*w*h) bytes of transmission (assuming image fully on screen)
181// Input: x     horizontal position of the bottom left corner of the image, columns from the left edge
182//        y     vertical position of the bottom left corner of the image, rows from the top edge
183//        image pointer to a 16-bit color BMP image
184//        w     number of pixels wide
185//        h     number of pixels tall
186// Output: none
187// Must be less than or equal to 128 pixels wide by 160 pixels high
188void ST7735_DrawBitmap(int16_t x, int16_t y, const uint16_t *image, int16_t w, int16_t h);
189
190//------------ST7735_DrawCharS------------
191// Simple character draw function.  This is the same function from
192// Adafruit_GFX.c but adapted for this processor.  However, each call
193// to ST7735_DrawPixel() calls setAddrWindow(), which needs to send
194// many extra data and commands.  If the background color is the same
195// as the text color, no background will be printed, and text can be
196// drawn right over existing images without covering them with a box.
197// Requires (11 + 2*size*size)*6*8 (image fully on screen; textcolor != bgColor)
198// Input: x         horizontal position of the top left corner of the character, columns from the left edge
199//        y         vertical position of the top left corner of the character, rows from the top edge
200//        c         character to be printed
201//        textColor 16-bit color of the character
202//        bgColor   16-bit color of the background
203//        size      number of pixels per character pixel (e.g. size==2 prints each pixel of font as 2x2 square)
204// Output: none
205void ST7735_DrawCharS(int16_t x, int16_t y, char c, int16_t textColor, int16_t bgColor, uint8_t size);
206
207//------------ST7735_DrawChar------------
208// Advanced character draw function.  This is similar to the function
209// from Adafruit_GFX.c but adapted for this processor.  However, this
210// function only uses one call to setAddrWindow(), which allows it to
211// run at least twice as fast.
212// Requires (11 + size*size*6*8) bytes of transmission (assuming image fully on screen)
213// Input: x         horizontal position of the top left corner of the character, columns from the left edge
214//        y         vertical position of the top left corner of the character, rows from the top edge
215//        c         character to be printed
216//        textColor 16-bit color of the character
217//        bgColor   16-bit color of the background
218//        size      number of pixels per character pixel (e.g. size==2 prints each pixel of font as 2x2 square)
219// Output: none
220void ST7735_DrawChar(int16_t x, int16_t y, char c, int16_t textColor, int16_t bgColor, uint8_t size);
221
222//------------ST7735_DrawString------------
223// String draw function.
224// 16 rows (0 to 15) and 21 characters (0 to 20)
225// Requires (11 + size*size*6*8) bytes of transmission for each character
226// Input: x         columns from the left edge (0 to 20)
227//        y         rows from the top edge (0 to 15)
228//        pt        pointer to a null terminated string to be printed
229//        textColor 16-bit color of the characters
230// bgColor is Black and size is 1
231// Output: number of characters printed
232uint32_t ST7735_DrawString(uint16_t x, uint16_t y, char *pt, int16_t textColor);;
233
234
235
236//********ST7735_SetCursor*****************
237// Move the cursor to the desired X- and Y-position.  The
238// next character will be printed here.  X=0 is the leftmost
239// column.  Y=0 is the top row.
240// inputs: newX  new X-position of the cursor (0<=newX<=20)
241//         newY  new Y-position of the cursor (0<=newY<=15)
242// outputs: none
243void ST7735_SetCursor(uint32_t newX, uint32_t newY);
244
245//-----------------------ST7735_OutUDec-----------------------
246// Output a 32-bit number in unsigned decimal format
247// Position determined by ST7735_SetCursor command
248// Color set by ST7735_SetTextColor
249// Input: 32-bit number to be transferred
250// Output: none
251// Variable format 1-10 digits with no space before or after
252void ST7735_OutUDec(uint32_t n);
253
254
255//------------ST7735_SetRotation------------
256// Change the image rotation.
257// Requires 2 bytes of transmission
258// Input: m new rotation value (0 to 3)
259// Output: none
260void ST7735_SetRotation(uint8_t m) ;
261
262
263//------------ST7735_InvertDisplay------------
264// Send the command to invert all of the colors.
265// Requires 1 byte of transmission
266// Input: i 0 to disable inversion; non-zero to enable inversion
267// Output: none
268void ST7735_InvertDisplay(int i) ;
269
270// graphics routines
271// y coordinates 0 to 31 used for labels and messages
272// y coordinates 32 to 159  128 pixels high
273// x coordinates 0 to 127   128 pixels wide
274
275// *************** ST7735_PlotClear ********************
276// Clear the graphics buffer, set X coordinate to 0
277// This routine clears the display
278// Inputs: ymin and ymax are range of the plot
279// Outputs: none
280void ST7735_PlotClear(int32_t ymin, int32_t ymax);
281
282// *************** ST7735_PlotPoint ********************
283// Used in the voltage versus time plot, plot one point at y
284// It does output to display
285// Inputs: y is the y coordinate of the point plotted
286// Outputs: none
287void ST7735_PlotPoint(int32_t y);
288
289// *************** ST7735_PlotLine ********************
290// Used in the voltage versus time plot, plot line to new point
291// It does output to display
292// Inputs: y is the y coordinate of the point plotted
293// Outputs: none
294void ST7735_PlotLine(int32_t y);
295
296// *************** ST7735_PlotPoints ********************
297// Used in the voltage versus time plot, plot two points at y1, y2
298// It does output to display
299// Inputs: y1 is the y coordinate of the first point plotted
300//         y2 is the y coordinate of the second point plotted
301// Outputs: none
302void ST7735_PlotPoints(int32_t y1,int32_t y2);
303
304// *************** ST7735_PlotBar ********************
305// Used in the voltage versus time bar, plot one bar at y
306// It does not output to display until RIT128x96x4ShowPlot called
307// Inputs: y is the y coordinate of the bar plotted
308// Outputs: none
309void ST7735_PlotBar(int32_t y);
310
311// *************** ST7735_PlotdBfs ********************
312// Used in the amplitude versus frequency plot, plot bar point at y
313// 0 to 0.625V scaled on a log plot from min to max
314// It does output to display
315// Inputs: y is the y ADC value of the bar plotted
316// Outputs: none
317void ST7735_PlotdBfs(int32_t y);
318
319// *************** ST7735_PlotNext ********************
320// Used in all the plots to step the X coordinate one pixel
321// X steps from 0 to 127, then back to 0 again
322// It does not output to display
323// Inputs: none
324// Outputs: none
325void ST7735_PlotNext(void);
326
327// *************** ST7735_PlotNextErase ********************
328// Used in all the plots to step the X coordinate one pixel
329// X steps from 0 to 127, then back to 0 again
330// It clears the vertical space into which the next pixel will be drawn
331// Inputs: none
332// Outputs: none
333void ST7735_PlotNextErase(void);
334
335// Used in all the plots to write buffer to LCD
336// Example 1 Voltage versus time
337//    ST7735_PlotClear(0,4095);  // range from 0 to 4095
338//    ST7735_PlotPoint(data); ST7735_PlotNext(); // called 128 times
339
340// Example 2a Voltage versus time (N data points/pixel, time scale)
341//    ST7735_PlotClear(0,4095);  // range from 0 to 4095
342//    {   for(j=0;j<N;j++){
343//          ST7735_PlotPoint(data[i++]); // called N times
344//        }
345//        ST7735_PlotNext();
346//    }   // called 128 times
347
348// Example 2b Voltage versus time (N data points/pixel, time scale)
349//    ST7735_PlotClear(0,4095);  // range from 0 to 4095
350//    {   for(j=0;j<N;j++){
351//          ST7735_PlotLine(data[i++]); // called N times
352//        }
353//        ST7735_PlotNext();
354//    }   // called 128 times
355
356// Example 3 Voltage versus frequency (512 points)
357//    perform FFT to get 512 magnitudes, mag[i] (0 to 4095)
358//    ST7735_PlotClear(0,1023);  // clip large magnitudes
359//    {
360//        ST7735_PlotBar(mag[i++]); // called 4 times
361//        ST7735_PlotBar(mag[i++]);
362//        ST7735_PlotBar(mag[i++]);
363//        ST7735_PlotBar(mag[i++]);
364//        ST7735_PlotNext();
365//    }   // called 128 times
366
367// Example 4 Voltage versus frequency (512 points), dB scale
368//    perform FFT to get 512 magnitudes, mag[i] (0 to 4095)
369//    ST7735_PlotClear(0,511);  // parameters ignored
370//    {
371//        ST7735_PlotdBfs(mag[i++]); // called 4 times
372//        ST7735_PlotdBfs(mag[i++]);
373//        ST7735_PlotdBfs(mag[i++]);
374//        ST7735_PlotdBfs(mag[i++]);
375//        ST7735_PlotNext();
376//    }   // called 128 times
377
378// *************** ST7735_OutChar ********************
379// Output one character to the LCD
380// Position determined by ST7735_SetCursor command
381// Color set by ST7735_SetTextColor
382// Inputs: 8-bit ASCII character
383// Outputs: none
384extern "C" void ST7735_OutChar(char ch);
385
386//********ST7735_OutString*****************
387// Print a string of characters to the ST7735 LCD.
388// Position determined by ST7735_SetCursor command
389// Color set by ST7735_SetTextColor
390// The string will not automatically wrap.
391// inputs: ptr  pointer to NULL-terminated ASCII string
392// outputs: none
393extern "C" void ST7735_OutString(char *ptr);
394
395// ************** ST7735_SetTextColor ************************
396// Sets the color in which the characters will be printed
397// Background color is fixed at black
398// Input:  16-bit packed color
399// Output: none
400// ********************************************************
401void ST7735_SetTextColor(uint16_t color);
402
403// *************** Output_Init ********************
404// Standard device driver initialization function for printf
405// Initialize ST7735 LCD
406// Inputs: none
407// Outputs: none
408void Output_Init(void);
409
410// Clear display
411void Output_Clear(void);
412
413// Turn off display (low power)
414void Output_Off(void);
415
416// Turn on display
417void Output_On(void);
418
419// set the color for future output
420// Background color is fixed at black
421// Input:  16-bit packed color
422// Output: none
423void Output_Color(uint32_t newColor);
424
425void Delay1ms(uint32_t n);
426
427#endif