65 extern int tft_is_calibrated;
68 extern mat_t tft_calX,tft_calY;
83 window *winbottom = &_winbottom;
92 window *winearth = &_winearth;
101 window *wincube = &_wincube;
104 LOCAL
double degree = 0.0;
106 LOCAL
double deg_inc = 4;
108 LOCAL
double dscale_inc;
112 LOCAL
double dscale_max;
114 LOCAL
long count = 0;
148 unsigned long ret = 0;
170 printf(
"Clock task init failed\n");
181 struct ip_info getinfo;
190 ip_addr_t *addr = (ip_addr_t *)
safecalloc(
sizeof(ip_addr_t),1);
193 ipaddr_aton(
"206.108.0.131", addr);
194 sntp_setserver(1,addr);
195 ipaddr_aton(
"167.114.204.238", addr);
196 sntp_setserver(2,addr);
200 if(wifi_get_ip_info(0, &getinfo))
204 sntp_setserver(1, & getinfo.gw);
205 sntp_setserver(2, & getinfo.ip);
209 printf(
"NTP:0 failed to get GW address\n");
214 if( sntp_set_timezone(0) )
216 printf(
"NTP: set_timeone OK\n");
224 printf(
"NTP: set_timeone Failed\n");
231 if( (sec = sntp_get_current_timestamp()) > 10 )
260 printf(
"Zone: %d\n", (
int) sntp_get_timezone());
284 printf(
"Command:[%s]\n",buffer);
287 printf(
"unknown command:[%s]\n", buffer);
321 #define VSCALE (VERROR*((R1+R2)/R2)/1024.0) 337 return( ((
float)system_adc_read()) *
VSCALE );
361 struct ip_info getinfo;
396 if(tft_is_calibrated)
401 tft_printf(winmsg,
"X:%d,Y:%d\n",(
int)X,(
int)Y);
417 #endif // VOLTAGE_TEST 423 tft_printf(wintop,
"Iter:% 10ld, %+7.2f\n", count, degree);
443 dscale += dscale_inc;
450 if(dscale < dscale_max/2)
452 dscale_inc = -dscale_inc;
454 if(dscale > dscale_max)
456 dscale_inc = -dscale_inc;
508 if(wifi_get_ip_info(0, &getinfo))
519 system_get_free_heap_size(), connections);
526 wifi_station_get_rssi());
527 #endif // DEBUG_STATS 538 printf(
"Error: loop() task overrun\n");
549 printf(
"Error: loop() entered with spi_cs = %d\n",ret);
561 printf(
"Error: loop() entered with spi_cs = %d\n",ret);
571 #if ILI9341_DEBUG & 1 573 void read_tests(
window *win)
582 printf(
"x:%d,y:%d,c:%04x\n", x,y,buffer[x]);
613 "setdate YYYY MM DD HH:MM:SS\n" 647 if (
MATCHARGS(ptr,
"help", (ind+0),argc ))
661 if (
MATCHARGS(ptr,
"adf4351", (ind + 1) ,argc))
663 adf4351_cmd(argc,argv);
667 if (
MATCHARGS(ptr,
"setdate", (ind + 1) ,argc))
672 if (
MATCHARGS(ptr,
"display_clock", (ind + 0) ,argc))
677 if (
MATCHARGS(ptr,
"time", (ind + 0) ,argc))
683 if (
MATCHARGS(ptr,
"connection", (ind + 0) ,argc))
685 printf(
"connections:%d\n", connections);
688 if (
MATCHARGS(ptr,
"mem", (ind + 0) ,argc))
693 if (
MATCHARGS(ptr,
"timetest", (ind + 1) ,argc))
699 if (
MATCHARGS(ptr,
"calibrate", (ind + 1) ,argc))
701 int ret =
atoi(argv[ind++]);
706 setup_windows(ret & 3,0);
709 if (
MATCHARGS(ptr,
"calibrate_test", (ind + 1) ,argc))
711 int ret =
atoi(argv[ind++]);
717 setup_windows(ret & 3,0);
720 if (
MATCHARGS(ptr,
"rotate", (ind + 1) ,argc))
723 int ret =
atoi(argv[ind++]);
725 setup_windows(ret & 3,0);
729 if (
MATCHARGS(ptr,
"draw", (ind + 1) ,argc))
731 char *ptr = argv[ind++];
742 if (
MATCHARGS(ptr,
"pixel", (ind + 0) ,argc))
753 printf(
"pixel(%d,%d): %04x\n", x,y,c);
763 ICACHE_RODATA_ATTR
uint8_t xxx[] = { 1,2,3,4,5,6,7,8 };
768 void test_flashio(
window *win)
791 unsigned char byte8[
sizeof(
unsigned int)];
793 volatile union UUU u;
795 printf(
"Byte Order of 0x12345678:\n");
797 for (i=0; i <
sizeof(
unsigned int); i++)
798 printf(
"byte[%d] = %02x\n", i, u.byte8[i]);
801 printf(
"sizeof (double) = %d\n",
sizeof (
double ) );
802 printf(
"sizeof (float) = %d\n",
sizeof (
float ) );
803 printf(
"sizeof (long long) = %d\n",
sizeof (
long long ) );
804 printf(
"sizeof (long) = %d\n",
sizeof (
long ) );
805 printf(
"sizeof (int) = %d\n",
sizeof (
int ) );
806 printf(
"sizeof (char) = %d\n",
sizeof (
char ) );
808 printf(
"long: %ld\n", 123456789
L);
809 printf(
"unsigned long: %lu\n", 123456789
L);
810 printf(
"long hex: %lx\n", 123456789
L);
812 printf(
"int : %d\n", 123456789
L);
813 printf(
"unsigned int: %u\n", 123456789
L);
814 printf(
"int hex: %lx\n", 123456789
L);
816 printf(
"int: %d\n", 12345);
817 printf(
"unsigned int: %u\n", 12345);
818 printf(
"int hex: %x\n", 12345);
823 setup_windows(
int rotation,
int debug)
835 #if ILI9341_DEBUG & 1 837 printf(
"\nDisplay ID=%08lx\n",ID);
842 w = master->
w * 7 / 10;
880 w = master->
w * 7 / 10;
887 w, master->
h - (wintop->
h + winbottom->
h));
913 if(!tft_is_calibrated)
916 tft_printf(winmsg,
"Please Calibrate Display\n");
917 tft_printf(winmsg,
"serial command: calibrate N\n");
929 if(wincube->
w < wincube->
h)
930 dscale_max = wincube->
w/2;
932 dscale_max = wincube->
h/2;
935 dscale_inc = dscale_max / 100;
938 #if ILI9341_DEBUG & 1 941 printf(
"Test Display Read\n");
951 if(winearth->
w < winearth->
h)
952 tscale_max = winearth->
w;
954 tscale_max = winearth->
h;
985 REG_SET_BIT(0x3ff00014, BIT(0));
989 os_delay_us(200000
L);
995 os_delay_us(200000
L);
996 os_delay_us(200000
L);
999 printf(
"System init...\n");
1000 printf(
"ESP8266 multidevice project\n");
1001 printf(
" (c) 2014-2017 by Mike Gore\n");
1002 printf(
" GNU version 3\n");
1003 printf(
"-> https://github.com/magore/esp8266_ili9341\n");
1004 printf(
" GIT last pushed: %s\n", GIT_VERSION);
1005 printf(
" Last updated file: %s\n", LOCAL_MOD);
1012 printf(
"HSPI init...\n");
1015 printf(
"Timers init...\n");
1034 printf(
"ADF4351 init done\n");
1038 #ifdef FATFS_SUPPORT 1044 printf(
"SD Card init...\n");
1061 tft_calX =
MatRead(
"/tft_calX");
1062 tft_calY =
MatRead(
"/tft_calY");
1064 tft_is_calibrated = 0;
1066 tft_is_calibrated = 1;
1067 printf(
"TFT calibration %s\n", tft_is_calibrated ?
"YES" :
"NO");
1080 #ifdef TELNET_SERIAL 1081 printf(
"Setup Network Serial Bridge\n");
1082 bridge_task_init(23);
1086 printf(
"espconn_tcp_set_max_con(%d) != (%d) - failed!\n",
1089 printf(
"espconn_tcp_set_max_con(%d) = (%d) - success!\n",
1093 printf(
"Setup Network TFT Display Client\n");
1098 printf(
"Setup Network WEB SERVER\n");
1105 system_set_os_print(0);
MEMSPACE void tft_setRotation(uint8_t m)
Set Display rotation, applies to the master window only Set hardware display rotation and memory fill...
uint16_t tft_readPixel(window *win, int16_t x, int16_t y)
Read one pixel and return color in 1bit 565 RGB format We clip the window to the current view Note: R...
uint8_t ip_msg[]
test task Runs corrected cube demo from Sem Optionally wireframe Earth viewer
MEMSPACE void tft_set_textpos(window *win, int16_t x, int16_t y)
Set current window text pointer in characters (per current rotation) - overall font bounding box...
MEMSPACE void display_clock()
Display system time and optionally RTC time.
MEMSPACE_RO wire_p earth_data[]
void ets_timer_disarm(ETSTimer *ptimer)
MEMSPACE void initialize_clock(int minwest)
initialize system time - if we have an RTC use it
MEMSPACE void servertest_message(window *win)
Network receive task.
MEMSPACE time_t mktime(tm_t *t)
convert tm_t structure to time_t local time epoch
Master include file for project Includes all project includes and defines here.
MEMSPACE void PrintRam()
Display Free memory and regions.
void hspi_init(uint32_t prescale, int hwcs)
HSPI Initiaization - with automatic chip select Pins: MISO GPIO12 MOSI GPIO13 CLK GPIO14 CS GPIO15 - ...
Common Linux/POSIX time functions.
MEMSPACE void tft_setTextColor(window *win, uint16_t fg, uint16_t bg)
====================================
Cordic_T X
Main Cordic routine - used for basic trig and vector rotations We use fixed point numbers...
MEMSPACE void set_dst(time_t epoch)
Set DST start and end time for the given epoch year.
void drawSVG(window *win, int16_t x, int16_t y, int16_t c, float scale, uint16_t color, int16_t fill)
uint8_t spi_chip_select_status()
SPI CS pin status return CS GPIO pin number or 0xff.
MEMSPACE void posix_help(int full)
MEMSPACE char * fgets(char *str, int size, FILE *stream)
get a string from stdin See fdevopen() sets stream->put get for TTY devices
void ETSTimerFunc(void *timer_arg)
MEMSPACE void setup_networking()
Code fragments if(!wifi_station_dhcpc_stop()) printf( "ERROR wifi_station_dhcpc_stop() \n ");...
MEMSPACE int setdate_r(char *buf)
Set date and time from string in this format "YYYY MM DD HH:MM:SS".
uint8_t read_flash8(uint8_t *p)
MEMSPACE void ms_init()
Initialize 1000HZ timer task.
int kbhiteol(int uart_no)
Has an EOL been read on stdin ?
MEMSPACE void print_dst_gmt()
print start/stop for DST as GMT for this year
MEMSPACE WEAK_ATR char * strncpy(char *dest, const char *src, size_t size)
copy a string of at most N characters
MEMSPACE void tft_set_font(window *win, uint16_t index)
Set current font size (per current rotation)
MEMSPACE int set_timers(void(*handler)(void), int timer)
Install a user timer task.
float adc_read()
return system_adc_read scaled to a float T_OUT pin is connected to the junction of a voltage divider ...
MEMSPACE void XPT2046_spi_init(void)
MEMSPACE time_t time(time_t *t)
Return second from epoch - POSIX function.
MEMSPACE void setup(void)
main() Initialize user task
MEMSPACE int split_args(char *str, char *argv[], int max)
Split string into arguments stored in argv[] We split source string into arguments Warning: source st...
MEMSPACE int fatfs_tests(int argc, char *argv[])
FatFs test parser.
MEMSPACE char * ipv4_2str(uint32_t ip)
void spi_end(uint8_t pin)
SPI chip disable function wait for current tranaction to finish!
void ets_timer_setfn(ETSTimer *ptimer, ETSTimerFunc *pfunction, void *parg)
void chip_select_init(uint8_t pin)
CHIP select HAL.
uint32_t time_t
type of EPOCH result.
MEMSPACE void servertest_setup(int port)
Setup Server Task.
#define tft_RGBto565(r, g, b)
Pass 8-bit (each) R,G,B, get back 16-bit packed color ILI9341 defaults to MSB/LSB data so we have to ...
MEMSPACE char * ctime_gm(time_t *tp)
GMT version of POSIX ctime().
MEMSPACE_RO wire_p cube_points[]
CUBE data +/- 0.5 is a cube with sides of 1.0.
MEMSPACE unsigned long ms_read()
Read 1000HZ timer We loop in case the update of ms_time is not "atomic" - done in a single instructio...
Cordic Routines Handle angle outside of the first quadrant Added standalone test to verify CORDIC aga...
MEMSPACE int tft_map_test(window *win, int points)
MEMSPACE void tft_font_fixed(window *win)
MEMSPACE int mmc_init(int verbose)
Initialize MMC and FatFs interface, display diagnostics.
MEMSPACE char * asctime(tm_t *t)
Convert tm_t *t structure into POSIX asctime() ASCII string.
uint32_t read_flash32(uint8_t *p)
32 bits reads from Flash memory space Uses cpy_flash() to avoid alighnment problems ...
void tft_drawPixel(window *win, int16_t x, int16_t y, int16_t color)
Pixel functions
MEMSPACE int timetests(char *str, int check)
MEMSPACE tm_t * gmtime(time_t *tp)
Convert epoch GMT time_t *tp into POSIX static tm_t *t.
MEMSPACE void ms_clear()
Clear 1000HZ timer We loop in case the update of ms_time is not "atomic" - done in a single instructi...
MEMSPACE void print_dst()
print start/stop for DST as localtime for this year
XPT2046 calibration code.
MEMSPACE void uart_init(UartBaudRate uart0_br, UartBaudRate uart1_br)
initialize uart0 and uart1 Defaults: 8 = data bits, 1 = stop bits, no parity
#define stdin
define stdin, stdout and stderr
Various string and character functions.
MEMSPACE void XPT2046_task(void)
MEMSPACE int posix_tests(int argc, char *argv[])
POSIX tests.
MEMSPACE mat_t MatRead(char *name)
Read a matrix.
MEMSPACE void tft_font_var(window *win)
Set current font type to variable.
MEMSPACE void fatfs_help(int full)
Display FatFs test diagnostics help menu.
MEMSPACE void wdt_reset(void)
reset watchdog
MEMSPACE int user_tests(int argc, char *argv[])
help functions test parser
void tft_fillWin(window *win, uint16_t color)
Fill functions
void tft_readRect(window *win, int16_t x, int16_t y, int16_t w, int16_t h, uint16_t *color)
MEMSPACE int printf(const char *format,...)
MEMSPACE void init_timers()
Setup all timers tasksi and enable interrupts.
System memory and reset utilities.
MEMSPACE int MATCHARGS(char *str, char *pat, int min, int argc)
Match two strings and compare argument index Display message if the number of arguments is too few...
void wire_draw(window *win, const wire_p *wire, const wire_e *edge, point *view, int x, int y, double scale, uint16_t color)
uint16_t read_flash16(uint8_t *p)
16 bits reads from Flash memory space Uses cpy_flash() to avoid alighnment problems ...
void ms_task(void)
1000HZ timer task
MEMSPACE_RO wire_e cube_edges[]
MEMSPACE void tft_cleareol(window *win)
Character and String functions
MEMSPACE int MatWrite(char *name, mat_t MatW)
Write a matrix.
ili9341 driver inspired by Adafruit ili9341 code All code in this file has been rewritten by Mike Gor...
MEMSPACE int settimeofday(tv_t *tv, tz_t *tz)
Set current time struct timeval *tv and struct timezone *tz - POSIX function. We assume a GMT hardwar...
MEMSPACE int tft_printf(window *win, const char *fmt,...)
tft_printf function
MEMSPACE void safefree(void *p)
Safe free - Only free a pointer if it is in malloc memory range. We want to try to catch frees of sta...
MEMSPACE char * ctime(time_t *tp)
Convert local time_t *t epoch time into POSIX asctime() string buf[].
Wireframe CUBE data used by wireframe viewer The code handles fixed, proportional and bounding box fo...
MEMSPACE int tft_touch_key(window *win, uint16_t *X, uint16_t *Y)
void chip_addr_init()
ADDRESS select HAL.
MEMSPACE void web_init(int port)
Setup WEB server and accept connections.
MEMSPACE int atoi(const char *str)
Convert ASCII string to number in base 10.
MEMSPACE window * tft_init(void)
Initialize TFT.
int font_H(int font)
Get font height used for line to line spacing.
MEMSPACE void * safecalloc(size_t nmemb, size_t size)
Safe Calloc - Display Error message if Calloc fails.
MEMSPACE void tft_drawCircle(window *win, int16_t x0, int16_t y0, int16_t r, uint16_t color)
Draw a circle outline.
MEMSPACE int tft_touch_calibrate(window *win)
MEMSPACE void tft_window_init(window *win, int16_t x, int16_t y, int16_t w, int16_t h)
Initialize window structure we default values FIXME check x+w, y+h absolute limits against TFT limuts...
MEMSPACE void sep()
print seperator