ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
flash.c
Go to the documentation of this file.
1 
24 #include "user_config.h"
25 
26 #include <stdint.h>
27 #include <stdarg.h>
28 #include <string.h>
29 #include <math.h>
30 
31 #include "flash.h"
32 
33 #define USE_CACHE
34 // Cached flash read on 32bit boundry
35 #ifdef USE_CACHE
36 
42 // Cached address and data
47 {
48  uint8_t offset;
49  uint32_t addr = (uint32_t)p;
50 
51  offset = 3 & addr; // byte offset
52  addr &= ~3; // align 4 byte address
53 
54  if(addr != _addr)
55  {
56  _addr = addr;
57  _data = *(uint32_t *) _addr;
58  }
59  return(p8[offset]);
60 }
61 
62 
63 #else
70 {
71  uint8_t offset;
72  uint32_t data;
73  uint32_t addr = (uint32_t)p;
74  uint8_t *p8 = (uint8_t *) &data;
75 
76  offset = 3 & addr; // byte offset
77  addr &= ~3; // align 4 byte address
78  data = *(uint32_t *) addr;
79  return(p8[offset]);
80 }
81 #endif
82 
89 void cpy_flash(uint8_t *src, uint8_t *dest, int size)
90 {
91  int i;
92  for(i=0;i<size;++i)
93  {
94  dest[i] = read_flash8((uint8_t *)src+i);
95  }
96 }
97 
98 
104 {
105  uint16_t tmp;
106  cpy_flash(p,(uint8_t *)&tmp, 2);
107  return(tmp);
108 }
109 
110 
116 {
117  uint32_t tmp;
118  cpy_flash(p,(uint8_t *) &tmp, 4);
119  return(tmp);
120 }
121 
122 
127 uint64_t read_flash64(uint8_t *p)
128 {
129  uint64_t tmp;
130  cpy_flash(p,(uint8_t *) &tmp, 8);
131  return(tmp);
132 }
133 
134 
140 {
141  uint32_t tmp;
142  cpy_flash(p,(uint8_t *) &tmp, 4);
143  return(tmp);
144 }
145 
146 
151 int bittestv(unsigned char *ptr, int off)
152 {
153  int data;
154  data = read_flash8(ptr + (off>>3));
155  return( (data & (0x80 >> (off&7))) );
156 }
157 
158 
166 int bittestxy(unsigned char *ptr, int x, int y, int w, int h)
167 {
168  int off;
169 
170  if(y < 0 || y > h)
171  {
172  return 0;
173  }
174  if(x < 0 || x > w)
175  {
176  return 0;
177  }
178  off = y * w + x;
179  return(bittestv(ptr, off));
180 }
181 
unsigned short uint16_t
Definition: send.c:18
Master include file for project Includes all project includes and defines here.
void cpy_flash(uint8_t *src, uint8_t *dest, int size)
Copy data from Flash to Ram Uses flash_read8() to avoid alighnment problems.
Definition: flash.c:89
int16_t y[XYSTACK+2]
Definition: ili9341.c:372
uint8_t read_flash8(uint8_t *p)
Definition: flash.c:46
unsigned int uint32_t
Definition: send.c:19
uint32_t _addr
Read bit bit value from flash Supports 8 bits reads from memory spaced that must have 32bit aligned d...
Definition: flash.c:43
uint64_t read_flash64(uint8_t *p)
64 bits reads from Flash memory space Uses cpy_flash() to avoid alighnment problems ...
Definition: flash.c:127
int16_t x[XYSTACK+2]
Definition: ili9341.c:371
uint32_t read_flash32(uint8_t *p)
32 bits reads from Flash memory space Uses cpy_flash() to avoid alighnment problems ...
Definition: flash.c:115
int bittestv(unsigned char *ptr, int off)
Test bit in byte array.
Definition: flash.c:151
uint32_t read_flash_ptr(uint8_t *p)
Pointer read from Flash memory space Uses cpy_flash() to avoid alighnment problems.
Definition: flash.c:139
int bittestxy(unsigned char *ptr, int x, int y, int w, int h)
Test bit in w * h size bit array usng x and y offsets.
Definition: flash.c:166
uint16_t read_flash16(uint8_t *p)
16 bits reads from Flash memory space Uses cpy_flash() to avoid alighnment problems ...
Definition: flash.c:103
unsigned char uint8_t
Definition: send.c:17
uint32_t _data
Definition: flash.c:44
Flash read and bit test utilities.
uint8_t * p8
Definition: flash.c:45