Subversion Repositories DashDisplay

Rev

Rev 4 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4 Rev 5
Line 18... Line 18...
18
 This code is taken from the ADAfruit library - it is used for playing with an OLED screen
18
 This code is taken from the ADAfruit library - it is used for playing with an OLED screen
19
 
19
 
20
 *********************************************************************/
20
 *********************************************************************/
21
#include <stdint.h>
21
#include <stdint.h>
22
#include <string.h>
22
#include <string.h>
23
#include "stm32f1xx_hal.h"
-
 
24
#include "SSD1306.h"
23
#include "SSD1306.h"
-
 
24
#include "stm32f1xx_hal_conf.h"
-
 
25
#include "stm32f1xx_hal.h"
-
 
26
 
25
 
27
 
26
#define swap(x,y) { typeof(x)t = x; x=y; y=t; }
28
#define swap(x,y) { typeof(x)t = x; x=y; y=t; }
27
#define abs(x)      ((x)>0?(x):-(x))
29
#define abs(x)      ((x)>0?(x):-(x))
28
 
30
 
29
static uint8_t rotation = 0;
31
static uint8_t rotation = 0;
Line 86... Line 88...
86
 
88
 
87
inline void fastSPIwrite(uint8_t d) {
89
inline void fastSPIwrite(uint8_t d) {
88
        uint8_t buffer[1];
90
        uint8_t buffer[1];
89
        buffer[0] = d;
91
        buffer[0] = d;
90
// todo chipselect based on 'cd' buffer choice
92
// todo chipselect based on 'cd' buffer choice
-
 
93
   if(cd==0)
-
 
94
   {
-
 
95
           HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_RESET);
-
 
96
   }
-
 
97
   if(cd==1)
-
 
98
   {
-
 
99
           HAL_GPIO_WritePin(SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_RESET);
-
 
100
   }
-
 
101
 
91
 
102
 
92
        HAL_SPI_Transmit(&hspi1, buffer, 1, 2);
103
        HAL_SPI_Transmit(&hspi1, buffer, 1, 2);
93
 
104
 
-
 
105
           if(cd==0)
-
 
106
           {
-
 
107
                   HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET);
-
 
108
           }
-
 
109
           if(cd==1)
-
 
110
           {
-
 
111
                   HAL_GPIO_WritePin(SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET);
-
 
112
           }
-
 
113
 
-
 
114
 
-
 
115
 
94
}
116
}
95
 
117
 
96
// the most basic function, set a single pixel
118
// the most basic function, set a single pixel
97
inline void drawPixel(int16_t x, int16_t y, uint16_t color) {
119
inline void drawPixel(int16_t x, int16_t y, uint16_t color) {
98
        if ((x < 0) || (x >= width()) || (y < 0) || (y >= height()))
120
        if ((x < 0) || (x >= width()) || (y < 0) || (y >= height()))
Line 146... Line 168...
146
        // bring out of reset
168
        // bring out of reset
147
        HAL_GPIO_WritePin(SPI_RESET_GPIO_Port, SPI_RESET_Pin, GPIO_PIN_SET);
169
        HAL_GPIO_WritePin(SPI_RESET_GPIO_Port, SPI_RESET_Pin, GPIO_PIN_SET);
148
        // turn on VCC (9V?)
170
        // turn on VCC (9V?)
149
 
171
 
150
        for (cd = 0; cd < 2; cd++) {
172
        for (cd = 0; cd < 2; cd++) {
-
 
173
                select_display(cd);
151
#if defined SSD1306_128_32
174
#if defined SSD1306_128_32
152
                // Init sequence for 128x32 OLED module
175
                // Init sequence for 128x32 OLED module
153
                ssd1306_command(SSD1306_DISPLAYOFF);// 0xAE
176
                ssd1306_command(SSD1306_DISPLAYOFF);// 0xAE
154
                ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV);// 0xD5
177
                ssd1306_command(SSD1306_SETDISPLAYCLOCKDIV);// 0xD5
155
                ssd1306_command(0x80);// the suggested ratio 0x80
178
                ssd1306_command(0x80);// the suggested ratio 0x80
Line 222... Line 245...
222
                ssd1306_command(SSD1306_NORMALDISPLAY);                 // 0xA6
245
                ssd1306_command(SSD1306_NORMALDISPLAY);                 // 0xA6
223
#endif
246
#endif
224
 
247
 
225
                ssd1306_command(SSD1306_DISPLAYON);               //--turn on oled panel
248
                ssd1306_command(SSD1306_DISPLAYON);               //--turn on oled panel
226
        }
249
        }
-
 
250
        select_display(0);
227
}
251
}
228
 
252
 
229
void invertDisplay(uint8_t i) {
253
void invertDisplay(uint8_t i) {
230
        if (i) {
254
        if (i) {
231
                ssd1306_command(SSD1306_INVERTDISPLAY);
255
                ssd1306_command(SSD1306_INVERTDISPLAY);
Line 341... Line 365...
341
                // set the cursor to
365
                // set the cursor to
342
                ssd1306_command(0xB0 + row); //set page address
366
                ssd1306_command(0xB0 + row); //set page address
343
                ssd1306_command(col & 0xf); //set lower column address
367
                ssd1306_command(col & 0xf); //set lower column address
344
                ssd1306_command(0x10 | (col >> 4)); //set higher column address
368
                ssd1306_command(0x10 | (col >> 4)); //set higher column address
345
 
369
 
-
 
370
 
346
                HAL_GPIO_WritePin(SPI1CD_GPIO_Port, SPI1CD_Pin, GPIO_PIN_SET);
371
                HAL_GPIO_WritePin(SPI1CD_GPIO_Port, SPI1CD_Pin, GPIO_PIN_SET);
-
 
372
                   if(cd==0)
-
 
373
                   {
-
 
374
                           HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_RESET);
-
 
375
                   }
-
 
376
                   if(cd==1)
-
 
377
                   {
-
 
378
                           HAL_GPIO_WritePin(SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_RESET);
-
 
379
                   }
-
 
380
 
-
 
381
 
-
 
382
 
-
 
383
 
347
                HAL_SPI_Transmit(&hspi1,
384
                HAL_SPI_Transmit(&hspi1,
348
                                (uint8_t *) (&display_buffer[cd]) + row * SSD1306_LCDWIDTH,
385
                                (uint8_t *) (&display_buffer[cd]) + row * SSD1306_LCDWIDTH,
349
                                SSD1306_LCDWIDTH, 100);
386
                                SSD1306_LCDWIDTH, 100);
-
 
387
                   if(cd==0)
-
 
388
                   {
-
 
389
                           HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET);
-
 
390
                   }
-
 
391
                   if(cd==1)
-
 
392
                   {
-
 
393
                           HAL_GPIO_WritePin(SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET);
-
 
394
                   }
-
 
395
 
350
        }
396
        }
351
 
397
 
352
}
398
}
353
 
399
 
354
// clear everything
400
// clear everything