Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
sif_ssd1608.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023, Cascoda Ltd.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the copyright holder nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
36 #ifndef SIF_SIF_SSD1608_H
37 #define SIF_SIF_SSD1608_H
38 
39 #include <stdint.h>
40 #include "ca821x_error.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /***********************************************************/
47 /********************* Pin connections *********************/
48 /***********************************************************/
49 /*
50  Pin config for M2351:
51  |---+- BUSY - Pin 31 (GPIO PB.5)
52  |---+- RST - Pin 15 (GPIO PA.15) on Chili2D, Pin 5 (GPIO PB.12) on Devboard
53  |---+- DC - Pin 34 (GPIO PB.2)
54  |---+- CS - GND
55  |---+- CLK - Pin 33 (GPIO PB.3)
56  |---+- DIN - Pin 32 (GPIO PB.4)
57  |---+- GND - (Pins 3/14/16/18-25/27/30)
58  |---+- VCC - Pin 13
59 
60 */
61 
62 /* Pin configuration */
63 #define SIF_SSD1608_BUSY_PIN 31
64 
65 #if (CASCODA_CHILI2_CONFIG == 2)
66 #define SIF_SSD1608_RST_PIN 5
67 #else
68 #define SIF_SSD1608_RST_PIN 15
69 #endif
70 
71 #define SIF_SSD1608_DC_PIN 34
72 //#define SIF_SSD1608_CS_PIN 34
73 
74 /* BUSY Timeout in [ms] */
75 #define SIF_SSD1608_BUSY_TIMEOUT 4000
76 
77 /* Actual physical display resolution (in pixels) */
78 #define SIF_SSD1608_WIDTH_PHYSICAL 200
79 #define SIF_SSD1608_HEIGHT_PHYSICAL 200
80 
81 #ifdef EPAPER_FULL_RESOLUTION
82 #define SIF_SSD1608_WIDTH_WINDOW SIF_SSD1608_WIDTH_PHYSICAL
83 #define SIF_SSD1608_HEIGHT_WINDOW SIF_SSD1608_HEIGHT_PHYSICAL
84 
85 #define SIF_SSD1608_WIDTH SIF_SSD1608_WIDTH_PHYSICAL
86 #define SIF_SSD1608_HEIGHT SIF_SSD1608_HEIGHT_PHYSICAL
87 #else
88 // Display resolution that the window will be set to upon initialization
89 // Note: 192 was chosen because it is the closest number to 200, that is a
90 // multiple of 8 after having been divided by 2. (The problem with 200 is that
91 // 200/2 is 100, which is not divisible by 8).
92 #define SIF_SSD1608_WIDTH_WINDOW 192
93 #define SIF_SSD1608_HEIGHT_WINDOW 200
94 
95 // Display resolution that the image buffer will be set to. This
96 // is the actual display resolution that ends up being used.
97 // This is done to save memory (200x200 resolution requires an image buffer
98 // of 5000 bytes, whereas 96*100 only requires 1200).
99 #define SIF_SSD1608_WIDTH (SIF_SSD1608_WIDTH_WINDOW / 2)
100 #define SIF_SSD1608_HEIGHT (SIF_SSD1608_WIDTH_WINDOW / 2)
101 #endif // EPAPER_FULL_RESOLUTION
102 
103 /* QR code image array size */
104 #define ARRAY_SIZE (SIF_SSD1608_HEIGHT * SIF_SSD1608_WIDTH / 8)
105 
106 /* Display update mode */
107 typedef enum
108 {
112 
113 /* Clear or no clear */
114 typedef enum
115 {
119 
120 /* update times in [ms] for scheduling when not waiting for busy signal */
121 #define SIF_SSD1608_TUPDATE_PARTIAL 350
122 
123 /* CAUTION: Don't increase this number. We have observed that this results
124 in the display often getting corrupted after a full update!! */
125 #define SIF_SSD1608_TUPDATE_FULL 1050
126 
127 /* flag to avoid re-entry into display update functions when not waiting for busy */
128 extern bool sif_ssd1608_display_is_busy;
129 
130 /* functions */
131 
132 /******************************************************************************/
133 /***************************************************************************/
139 
140 /******************************************************************************/
141 /***************************************************************************/
145 void SIF_SSD1608_Deinitialise(void);
146 
147 /******************************************************************************/
148 /***************************************************************************/
152 void SIF_SSD1608_ClearDisplay(void);
153 
154 /******************************************************************************/
155 /***************************************************************************/
160 
161 /******************************************************************************/
162 /***************************************************************************/
166 void SIF_SSD1608_DeepSleep(void);
167 
168 /******************************************************************************/
169 /***************************************************************************/
180 ca_error SIF_SSD1608_overlay_qr_code(const char *text, uint8_t *image, uint8_t scale, uint8_t x, uint8_t y);
181 
182 /******************************************************************************/
183 /***************************************************************************/
196 void SIF_SSD1608_DisplayImage(const uint8_t *image, SIF_SSD1608_Clear_Mode mode, bool full_resolution);
197 
198 /******************************************************************************/
199 /***************************************************************************/
213 void SIF_SSD1608_DisplayImageNoWait(const uint8_t *image, SIF_SSD1608_Clear_Mode mode, bool full_resolution);
214 
215 /******************************************************************************/
216 /***************************************************************************/
222 ca_error SIF_SSD1608_PowerDown(void *aContext);
223 
224 #ifdef __cplusplus
225 }
226 #endif
227 
232 #endif
233 // SIF_SIF_SSD1608_H
Global error declarations for use across the Cascoda SDK.
SIF_SSD1608_Update_Mode
Definition: sif_ssd1608.h:108
void SIF_SSD1608_DisplayImageNoWait(const uint8_t *image, SIF_SSD1608_Clear_Mode mode, bool full_resolution)
Same as SIF_SSD1608_DisplayImage() but does not wait for busy.
Definition: sif_ssd1608.c:682
bool sif_ssd1608_display_is_busy
Definition: sif_ssd1608.c:68
void SIF_SSD1608_StrongClearDisplay(void)
Clears the display many times to make sure there is no ghost image.
Definition: sif_ssd1608.c:631
SIF_SSD1608_Clear_Mode
Definition: sif_ssd1608.h:115
void SIF_SSD1608_Deinitialise(void)
EINK De-Initialisation.
Definition: sif_ssd1608.c:381
ca_error SIF_SSD1608_PowerDown(void *aContext)
callback function for power-down when not waiting for busy signal
Definition: sif_ssd1608.c:700
ca_error SIF_SSD1608_Initialise(SIF_SSD1608_Update_Mode mode)
EINK Initialisation.
Definition: sif_ssd1608.c:339
void SIF_SSD1608_DeepSleep(void)
Enter deep sleep mode.
Definition: sif_ssd1608.c:638
ca_error SIF_SSD1608_overlay_qr_code(const char *text, uint8_t *image, uint8_t scale, uint8_t x, uint8_t y)
Creates a QR code and overlays it on top of a pre-existing image at the given coordinates.
Definition: sif_ssd1608.c:646
void SIF_SSD1608_ClearDisplay(void)
Clears the display.
Definition: sif_ssd1608.c:607
void SIF_SSD1608_DisplayImage(const uint8_t *image, SIF_SSD1608_Clear_Mode mode, bool full_resolution)
Follows Routines for clearing, waiting and displaying the image.
Definition: sif_ssd1608.c:663
@ PARTIAL_UPDATE
Definition: sif_ssd1608.h:110
@ FULL_UPDATE
Definition: sif_ssd1608.h:109
@ WITH_CLEAR
Definition: sif_ssd1608.h:116
@ WITHOUT_CLEAR
Definition: sif_ssd1608.h:117
ca_error
Cascoda error type.
Definition: ca821x_error.h:51