Advertisement
Guest User

Untitled

a guest
Dec 5th, 2022
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 35.74 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdbool.h>
  5. #include <dirent.h>
  6. #include <fcntl.h>
  7. #include <assert.h>
  8.  
  9. #include <sched.h>      // To set the priority on linux
  10.  
  11. #include <sys/mman.h>
  12. #include <sys/types.h>
  13. #include <sys/stat.h>
  14.  
  15. #include <unistd.h>
  16. #include <math.h>
  17.  
  18. // Define which Raspberry Pi board are you using. Take care to have defined only one at time.
  19. #define RPI
  20. //#define RPI2
  21.  
  22. #ifdef RPI
  23. #define BCM2708_PERI_BASE       0x20000000
  24. #define GPIO_BASE               (BCM2708_PERI_BASE + 0x200000)  // GPIO controller
  25. //#define BSC0_BASE         (BCM2708_PERI_BASE + 0x205000)  // I2C0 controller
  26. #define BSC0_BASE       (BCM2708_PERI_BASE + 0x804000)  // I2C1 controller
  27. #define SYST_BASE       (BCM2708_PERI_BASE + 0x3000)   
  28. #endif
  29.  
  30. #ifdef RPI2
  31. #define BCM2708_PERI_BASE       0x3F000000
  32. #define GPIO_BASE               (BCM2708_PERI_BASE + 0x200000)  // GPIO controller. Maybe wrong. Need to be tested.
  33. #define BSC0_BASE       (BCM2708_PERI_BASE + 0x804000)  // I2C controller  
  34. #endif 
  35.  
  36. #define PAGE_SIZE       (4*1024)
  37. #define BLOCK_SIZE      (4*1024)
  38.  
  39. #define SYST_CS  0
  40. #define SYST_CLO 1
  41. #define SYST_CHI 2
  42.  
  43. // IO Acces
  44. struct bcm2835_peripheral {
  45.     unsigned long addr_p;
  46.     int mem_fd;
  47.     void *map;
  48.     volatile unsigned int *addr;
  49. };
  50.  
  51. struct bcm2835_peripheral gpio = {GPIO_BASE};
  52. struct bcm2835_peripheral bsc0 = {BSC0_BASE};
  53. struct bcm2835_peripheral syst = {SYST_BASE};
  54.  
  55. // GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y)
  56. #define INP_GPIO(g)     *(gpio.addr + ((g)/10)) &= ~(7<<(((g)%10)*3))
  57. #define OUT_GPIO(g)     *(gpio.addr + ((g)/10)) |=  (1<<(((g)%10)*3))
  58. #define SET_GPIO_ALT(g,a) *(gpio.addr + (((g)/10))) |= (((a)<=3?(a) + 4:(a)==4?3:2)<<(((g)%10)*3))
  59.  
  60. #define GPIO_SET    *(gpio.addr + 7)  // sets   bits which are 1 ignores bits which are 0
  61. #define GPIO_CLR    *(gpio.addr + 10) // clears bits which are 1 ignores bits which are 0
  62.  
  63. #define GPIO_READ(g)    *(gpio.addr + 13) &= (1<<(g))
  64.  
  65. // I2C macros
  66. // The following parameters relate to registers in the Boardcom Serial Controller #0 (BSC0) - they are pointers to the BSC0 address plus an offset relating to a specific register
  67. #define BSC0_C  *(bsc0.addr + 0x00)     // Control register address
  68. #define BSC0_S  *(bsc0.addr + 0x01)     // Status register address
  69. #define BSC0_DLEN   *(bsc0.addr + 0x02) // Data length register address
  70. #define BSC0_A  *(bsc0.addr + 0x03)     // Slave register register address
  71. #define BSC0_FIFO   *(bsc0.addr + 0x04) // First In First Out buffer address
  72.  
  73. // The following parameters relate to specific bits of the Control Register
  74. // These are set via bitwise left shifting of the value 1 via the logical operator <<
  75. #define BSC_C_I2CEN (1 << 15)       // enables BSC operations - 0 prevents transfers but register accesses is still permitted
  76. #define BSC_C_INTR  (1 << 10)       // enable/Disable interrupt on RX - 0 prevents interrupts on RXR condition - 1 generates an interrupt while RXR = 1
  77. #define BSC_C_INTT  (1 << 9)        // writing a 0 disables interrupts on TXW - 1 enables; TXW indicates whether the FIFO is full and ready for transfer/reading
  78. #define BSC_C_INTD  (1 << 8)        // 1 enables interrupts to alter the DONE condition on completion of a transfer (0 disables). The interrupt remains active until the DONE condition is cleared by writing a 1 to the I2CS.DONE field.
  79. #define BSC_C_ST    (1 << 7)        // starts a new data transfer - writing to this field is a one-shot operation (it always reads as zero)
  80. #define BSC_C_CLEAR (1 << 4)        // clears the FIFO - writing to this field is a one-shot operation (it always reads as zero)
  81. #define BSC_C_READ  1           // specifies transfer type as read
  82.  
  83. // The logical OR opporator, | , is used here to combine the bits above into commands for the control register
  84. #define START_READ  BSC_C_I2CEN|BSC_C_ST|BSC_C_CLEAR|BSC_C_READ // Initialisation of the control register before reading
  85. #define START_WRITE BSC_C_I2CEN|BSC_C_ST                // Initialisation of the control register before writing
  86.  
  87. // The following parameters relate to specific bits of the Status Register
  88. // These indicate the status of the First In First Out (FIFO) buffer and current data transfer in general
  89. // These are again set via bitwise left shifting of the value 1 via the logical operator <<
  90. #define BSC_S_CLKT  (1 << 9)        // is set to indicate that the slave is holding the SCL signal high for an extended time period (clock stretching) - reset by writing a 1 (writing a 0 to the field has no effect)
  91. #define BSC_S_ERR   (1 << 8)        // is set to indicate that the slave has failed to acknowledge either its address or a data byte written to it - reset by writing a 1 (writing a 0 to the field has no effect)
  92. #define BSC_S_RXF   (1 << 7)        // is set to indicate that the FIFO is full
  93. #define BSC_S_TXE   (1 << 6)        // is set to indicate that the FIFO is empty
  94. #define BSC_S_RXD   (1 << 5)        // is set to indicate that the FIFO contains at least one byte of data
  95. #define BSC_S_TXD   (1 << 4)        // is set to indicate that the FIFO has space for at least one more byte of data
  96. #define BSC_S_RXR   (1 << 3)        // generate interrupt to read data from the FIFO before it becomes full
  97. #define BSC_S_TXW   (1 << 2)        // generate an interrupt to write more data to the FIFO to complete the current transfer
  98. #define BSC_S_DONE  (1 << 1)        // is set to indicate that the transfer has completed
  99. #define BSC_S_TA    1           // is set to indicate the activity of the BSC (1 when busy, 0 when idle)
  100.  
  101. // The logical OR opporator | is used here to combine the bits above into command to clear the status register
  102. #define CLEAR_STATUS    BSC_S_CLKT|BSC_S_ERR|BSC_S_DONE     // reset/initialise ready for fresh transfer
  103.  
  104. // Exposes the physical address defined in the passed structure using mmap on /dev/mem
  105. unsigned short map_peripheral(struct bcm2835_peripheral *p)
  106. {
  107.     // Open /dev/mem
  108.     if ((p->mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {
  109.         printf("Failed to open /dev/mem, try checking permissions.\n");
  110.         return 0;
  111.     }
  112.  
  113.     p->map = mmap(
  114.          NULL,
  115.          BLOCK_SIZE,
  116.          PROT_READ|PROT_WRITE,
  117.          MAP_SHARED,
  118.          p->mem_fd,  // File descriptor to physical memory virtual file '/dev/mem'
  119.          p->addr_p      // Address in physical map that we want this memory block to expose
  120.     );
  121.  
  122.     if (p->map == MAP_FAILED) {
  123.         perror("mmap");
  124.         return 0;
  125.     }
  126.  
  127.     p->addr = (volatile unsigned int *)p->map;
  128.  
  129.     return 1;
  130. }
  131.  
  132. void unmap_peripheral(struct bcm2835_peripheral *p)
  133. {
  134.  
  135.     munmap(p->map, BLOCK_SIZE);
  136.     close(p->mem_fd);
  137. }
  138.  
  139. void dump_bsc_status(void)
  140. {
  141.     unsigned int s = BSC0_S;
  142.  
  143.     printf("BSC0_S: ERR=%d  RXF=%d  TXE=%d  RXD=%d  TXD=%d  RXR=%d  TXW=%d  DONE=%d  TA=%d\n",
  144.          (s & BSC_S_ERR) != 0,
  145.          (s & BSC_S_RXF) != 0,
  146.          (s & BSC_S_TXE) != 0,
  147.          (s & BSC_S_RXD) != 0,
  148.          (s & BSC_S_TXD) != 0,
  149.          (s & BSC_S_RXR) != 0,
  150.          (s & BSC_S_TXW) != 0,
  151.          (s & BSC_S_DONE) != 0,
  152.          (s & BSC_S_TA) != 0 );
  153. }
  154.  
  155. // Function to wait for the I2C transaction to complete
  156. void wait_i2c_done(void)
  157. {
  158.         // 5ms timeout for wait i2c done
  159.         unsigned short timeout = 50;
  160.  
  161.         while((!(BSC0_S & BSC_S_DONE)) && --timeout)
  162.             usleep(100);
  163.  
  164.         if(timeout == 0)
  165.             printf("wait_i2c_done() timeout! Something went wrong!\n");
  166. }
  167.  
  168. void i2c_init()
  169. {
  170.     INP_GPIO(0);
  171.     SET_GPIO_ALT(0, 0);
  172.     INP_GPIO(1);
  173.     SET_GPIO_ALT(1, 0);
  174. }
  175.  
  176. // Priority
  177.  
  178. int SetProgramPriority(int priorityLevel)
  179. {
  180.     struct sched_param sched;
  181.  
  182.     memset(&sched, 0, sizeof(sched));
  183.  
  184.     if (priorityLevel > sched_get_priority_max (SCHED_RR))
  185.         priorityLevel = sched_get_priority_max (SCHED_RR);
  186.  
  187.     sched.sched_priority = priorityLevel;
  188.  
  189.     return sched_setscheduler (0, SCHED_RR, &sched);
  190. }
  191.  
  192. #define PI_PUD_OFF  0
  193. #define PI_PUD_DOWN 1
  194. #define PI_PUD_UP   2
  195.  
  196. void gpioSetPullUpDown(unsigned gpionum, unsigned pud)
  197. {
  198.     *(gpio.addr + 37) = pud;
  199.  
  200.     usleep(20);
  201.  
  202.     *(gpio.addr + 38 + (gpionum>>5)) = (1<<(gpionum&0x1F));
  203.  
  204.     usleep(20);
  205.  
  206.     *(gpio.addr + 37) = 0;
  207.  
  208.     *(gpio.addr + 38 + (gpionum>>5)) = 0;
  209. }
  210.  
  211. int gpioGetMode(unsigned gpionum)
  212. {
  213.     int reg, shift;
  214.  
  215.     reg   =  gpionum/10;
  216.     shift = (gpionum%10) * 3;
  217.  
  218.     return (*(gpio.addr + reg) >> shift) & 7;
  219. }
  220.  
  221. int gpioRead(unsigned gpionum)
  222. {
  223.     if ((*(gpio.addr + 13 + (gpionum>>5)) & (1<<(gpionum&0x1F))) != 0)
  224.         return 1;
  225.     else
  226.         return 0;
  227. }
  228.  
  229. void gpioWrite(unsigned gpionum, unsigned level)
  230. {
  231.     if (level == 0)
  232.         *(gpio.addr + 10 + (gpionum>>5)) = (1<<(gpionum&0x1F));
  233.     else
  234.         *(gpio.addr + 7 + (gpionum>>5)) = (1<<(gpionum&0x1F));
  235. }
  236.  
  237. uint32_t gpioTick(void)
  238. {
  239.     return syst.addr[SYST_CLO];
  240. }
  241.  
  242. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  243.  
  244. /*------------------------------ SSD1306 128x64 definitions ---------------------------------*/
  245.  
  246. #define SSD1306_I2C_ADDRESS      0x3C
  247.  
  248. #define SSD1306_LCDWIDTH             128
  249. #define SSD1306_LCDHEIGHT            64
  250.  
  251. #define SSD1306_NORMALDISPLAY        0xA6
  252. #define SSD1306_INVERTDISPLAY        0xA7
  253. #define SSD1306_DISPLAYOFF           0xAE
  254. #define SSD1306_DISPLAYON            0xAF
  255. #define SSD1306_SETDISPLAYOFFSET     0xD3
  256. #define SSD1306_SETCOMPINS           0xDA
  257. #define SSD1306_SETVCOMDETECT        0xDB
  258. #define SSD1306_SETDISPLAYCLOCKDIV   0xD5
  259. #define SSD1306_SETPRECHARGE         0xD9
  260. #define SSD1306_SETCONTRAST          0x81
  261. #define SSD1306_DISPLAYALLON_RESUME  0xA4
  262. #define SSD1306_SETMULTIPLEX         0xA8
  263. #define SSD1306_SETLOWCOLUMN         0x00
  264. #define SSD1306_SETHIGHCOLUMN        0x10
  265. #define SSD1306_SETSTARTLINE         0x40
  266. #define SSD1306_MEMORYMODE           0x20
  267. #define SSD1306_COLUMNADDR           0x21
  268. #define SSD1306_PAGEADDR             0x22
  269. #define SSD1306_COMSCANINC           0xC0
  270. #define SSD1306_COMSCANDEC           0xC8
  271. #define SSD1306_SEGREMAP             0xA0
  272. #define SSD1306_CHARGEPUMP           0x8D
  273. #define SSD1306_EXTERNALVCC          0x01
  274. #define SSD1306_SWITCHCAPVCC         0x02
  275.  
  276. // Scrolling #defines
  277. #define SSD1306_ACTIVATE_SCROLL      0x2F
  278. #define SSD1306_DEACTIVATE_SCROLL                    0x2E
  279. #define SSD1306_SET_VERTICAL_SCROLL_AREA             0xA3
  280. #define SSD1306_RIGHT_HORIZONTAL_SCROLL              0x26
  281. #define SSD1306_LEFT_HORIZONTAL_SCROLL               0x27
  282. #define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29
  283. #define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL  0x2A
  284.  
  285. #define Set_Page_Start_Address_CMD                   0xB0
  286.  
  287. #define y_max   8
  288.  
  289. #define CMD 0x00
  290. #define DAT 0x40
  291.  
  292. void ssd1306_write(uint8_t cmd, uint8_t addr)
  293. {
  294.     BSC0_A = SSD1306_I2C_ADDRESS;
  295.  
  296.     BSC0_DLEN = 2;
  297.     BSC0_FIFO = cmd;
  298.     BSC0_FIFO = addr;  
  299.     BSC0_S = CLEAR_STATUS;
  300.     BSC0_C = START_WRITE;  
  301.     wait_i2c_done();
  302. }
  303.  
  304. void ssd1306_init(void)
  305. {
  306.     // Init sequence for Adafruit 128x64 OLED module
  307.     ssd1306_write(CMD, SSD1306_DISPLAYOFF);
  308.     ssd1306_write(CMD, SSD1306_SETDISPLAYCLOCKDIV);
  309.     ssd1306_write(CMD, 0x80);                             // the suggested ratio 0x80
  310.     ssd1306_write(CMD, SSD1306_SETMULTIPLEX);
  311.     ssd1306_write(CMD, 0x3F);                             // ratio 64
  312.     ssd1306_write(CMD, SSD1306_SETDISPLAYOFFSET);
  313.     ssd1306_write(CMD, 0x0);                              // no offset
  314.     ssd1306_write(CMD, SSD1306_SETSTARTLINE | 0x0);       // line #0
  315.     ssd1306_write(CMD, SSD1306_CHARGEPUMP);
  316.     ssd1306_write(CMD, 0x14);                             // internal vcc
  317.     ssd1306_write(CMD, SSD1306_MEMORYMODE);
  318.     ssd1306_write(CMD, 0x02);                             // page mode
  319.     ssd1306_write(CMD, SSD1306_SEGREMAP | 0x1);           // column 127 mapped to SEG0
  320.     ssd1306_write(CMD, SSD1306_COMSCANDEC);               // column scan direction reversed
  321.     ssd1306_write(CMD, SSD1306_SETCOMPINS);
  322.     ssd1306_write(CMD, 0x12);                             // alt COM pins, disable remap
  323.     ssd1306_write(CMD, SSD1306_SETCONTRAST);
  324.     ssd1306_write(CMD, 0x7F);                             // contrast level 127
  325.     ssd1306_write(CMD, SSD1306_SETPRECHARGE);
  326.     ssd1306_write(CMD, 0xF1);                             // pre-charge period (1, 15)
  327.     ssd1306_write(CMD, SSD1306_SETVCOMDETECT);
  328.     ssd1306_write(CMD, 0x40);                             // vcomh regulator level
  329.     ssd1306_write(CMD, SSD1306_DISPLAYALLON_RESUME);
  330.     ssd1306_write(CMD, SSD1306_NORMALDISPLAY);
  331.     ssd1306_write(CMD, SSD1306_DISPLAYON);
  332. }
  333.  
  334. #define FONT_WIDTH 42
  335. #define FONT_HEIGHT 62
  336.  
  337. const char font_bitmap[10][336] = {
  338.     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xE0, 0xF0, 0xF0,
  339.     0xF0, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0,
  340.     0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  341.     0xE0, 0xF8, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x0F, 0x07, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01,
  342.     0x01, 0x01, 0x01, 0x03, 0x03, 0x07, 0x0F, 0x1F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFE, 0xFC, 0xF0, 0x80,
  343.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F,
  344.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  345.     0x00, 0x00, 0x00, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00,
  346.     0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  347.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
  348.     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
  349.     0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  350.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
  351.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x80, 0x00,
  352.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  353.     0x80, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  354.     0x00, 0x00, 0x03, 0x0F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0xF0, 0xE0, 0xE0, 0xC0, 0xC0,
  355.     0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x1F,
  356.     0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  357.     0x00, 0x01, 0x03, 0x03, 0x07, 0x07, 0x07, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
  358.     0x07, 0x07, 0x07, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 0
  359.  
  360.     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  361.     0x80, 0x80, 0x80, 0xC0, 0xC0, 0xC0, 0xE0, 0xE0, 0xE0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00,
  362.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  363.     0xF8, 0xF8, 0xFC, 0xFC, 0xFC, 0x7E, 0x7E, 0x7E, 0x3F, 0x3F, 0x1F, 0x1F, 0x1F, 0x0F, 0xFF, 0xFF,
  364.     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  365.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  366.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
  367.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  368.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  369.     0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  370.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  371.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
  372.     0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  373.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  374.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
  375.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  376.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  377.     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  378.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  379.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
  380.     0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 1
  381.  
  382.     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xE0, 0xF0, 0xF0, 0xF0, 0xF8,
  383.     0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xC0, 0xC0,
  384.     0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF8, 0xFC,
  385.     0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F, 0x0F, 0x07, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  386.     0x01, 0x01, 0x03, 0x03, 0x07, 0x0F, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0xC0, 0x00,
  387.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x00, 0x00,
  388.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  389.     0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  390.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  391.     0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xFC, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F,
  392.     0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  393.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFF,
  394.     0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  395.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8,
  396.     0xFE, 0xFF, 0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  397.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  398.     0xE0, 0xF8, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xEF, 0xE7, 0xE3, 0xE1, 0xE0, 0xE0, 0xE0, 0xE0,
  399.     0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0,
  400.     0xE0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
  401.     0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
  402.     0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00, 0x00, 0x00}, // 2
  403.  
  404.     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xE0, 0xF0, 0xF0, 0xF0,
  405.     0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0,
  406.     0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF0,
  407.     0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F, 0x0F, 0x07, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01,
  408.     0x01, 0x01, 0x01, 0x03, 0x03, 0x07, 0x0F, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFC, 0xE0, 0x00,
  409.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00,
  410.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  411.     0x00, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  412.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0,
  413.     0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF8, 0xF8, 0xFC, 0xFC, 0xFE, 0xFF, 0xBF, 0x1F, 0x1F, 0x0F,
  414.     0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  415.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
  416.     0x07, 0x07, 0x07, 0x0F, 0x1F, 0x3F, 0xFF, 0xFF, 0xFE, 0xFE, 0xFC, 0xF8, 0xE0, 0x80, 0x00, 0x00,
  417.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0x00, 0x00, 0x00,
  418.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  419.     0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  420.     0x03, 0x0F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0,
  421.     0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F,
  422.     0x0F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  423.     0x01, 0x03, 0x03, 0x07, 0x07, 0x07, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
  424.     0x07, 0x07, 0x07, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 3
  425.  
  426.     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  427.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
  428.     0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  429.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xF0, 0xFC,
  430.     0xFE, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
  431.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  432.     0x00, 0x80, 0xE0, 0xF0, 0xFC, 0xFE, 0xFF, 0xFF, 0x3F, 0x1F, 0x07, 0x03, 0x00, 0x00, 0xFF, 0xFF,
  433.     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  434.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xF0, 0xFC, 0xFE, 0xFF, 0xFF, 0x3F, 0x1F, 0x07,
  435.     0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
  436.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xF0, 0xFC, 0xFF,
  437.     0xFF, 0xFF, 0x3F, 0x1F, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  438.     0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  439.     0x00, 0x00, 0x00, 0x7C, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E,
  440.     0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0xFF, 0xFF, 0xFF, 0xFF,
  441.     0xFF, 0xFF, 0xFF, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00,
  442.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  443.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
  444.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  445.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  446.     0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 4
  447.  
  448.     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
  449.     0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
  450.     0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  451.     0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
  452.     0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00,
  453.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  454.     0xFF, 0x07, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00,
  455.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  456.     0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E, 0x3F, 0x3F, 0x1F, 0x1F,
  457.     0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x3F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFE, 0xFE, 0xFC, 0xF8, 0xF0,
  458.     0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  459.     0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  460.     0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0x00, 0x00,
  461.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0x00, 0x00, 0x00,
  462.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  463.     0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  464.     0x01, 0x07, 0x1F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0,
  465.     0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0xE0, 0xF0, 0xF0, 0xF8, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x1F,
  466.     0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  467.     0x01, 0x03, 0x03, 0x07, 0x07, 0x07, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
  468.     0x07, 0x07, 0x07, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 5
  469.  
  470.     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  471.     0x80, 0x80, 0xC0, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x00,
  472.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  473.     0x00, 0x00, 0x80, 0xC0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFF, 0xFF, 0x7F, 0x3F, 0x1F, 0x1F, 0x0F, 0x0F,
  474.     0x07, 0x07, 0x07, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  475.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF8, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF,
  476.     0x1F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00,
  477.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  478.     0x00, 0x00, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF9, 0xF8, 0xFC, 0xFE, 0x7E, 0x3F, 0x3F,
  479.     0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x3F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFE, 0xFC, 0xFC, 0xF8,
  480.     0xF0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
  481.     0xFF, 0xFF, 0xFF, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  482.     0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0x00, 0x00,
  483.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0x80, 0x00,
  484.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  485.     0x00, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  486.     0x00, 0x00, 0x03, 0x0F, 0x1F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0,
  487.     0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x1F,
  488.     0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  489.     0x00, 0x01, 0x01, 0x03, 0x03, 0x07, 0x07, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
  490.     0x07, 0x07, 0x07, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 6
  491.  
  492.     {0x00, 0x00, 0x00, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0,
  493.     0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0,
  494.     0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07,
  495.     0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
  496.     0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x87, 0xE7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F,
  497.     0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  498.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,
  499.     0xF0, 0xFC, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  500.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  501.     0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xF0, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x0F, 0x03, 0x00,
  502.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  503.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xF8, 0xFE, 0xFF,
  504.     0xFF, 0xFF, 0x7F, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  505.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  506.     0x00, 0x00, 0xC0, 0xF0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x00,
  507.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  508.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
  509.     0x1F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  510.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  511.     0x08, 0x0E, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  512.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 7
  513.  
  514.     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xE0, 0xF0, 0xF0,
  515.     0xF0, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0,
  516.     0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  517.     0xF0, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x0F, 0x07, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01,
  518.     0x01, 0x01, 0x01, 0x03, 0x03, 0x07, 0x0F, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xF0, 0x80,
  519.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  520.     0xF1, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  521.     0x00, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  522.     0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0xBF, 0xFF, 0xFE, 0xFC, 0xF8, 0xF8,
  523.     0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF8, 0xF8, 0xFC, 0xFE, 0xFF, 0xFF, 0x3F, 0x1F, 0x0F,
  524.     0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF8,
  525.     0xFC, 0xFE, 0xFE, 0xFF, 0x7F, 0x1F, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
  526.     0x03, 0x07, 0x07, 0x0F, 0x0F, 0x1F, 0x3F, 0xFF, 0xFF, 0xFE, 0xFC, 0xF8, 0xF0, 0xC0, 0x00, 0x00,
  527.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x81, 0x00, 0x00,
  528.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  529.     0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  530.     0x00, 0x07, 0x1F, 0x3F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFC, 0xF8, 0xF0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0,
  531.     0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0xE0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
  532.     0x1F, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  533.     0x01, 0x03, 0x03, 0x07, 0x07, 0x07, 0x07, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
  534.     0x0F, 0x07, 0x07, 0x07, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 8
  535.  
  536.     {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xE0, 0xE0, 0xE0,
  537.     0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0x80, 0x00,
  538.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,
  539.     0xF0, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F, 0x0F, 0x07, 0x07, 0x07, 0x03, 0x03, 0x03, 0x03,
  540.     0x03, 0x03, 0x07, 0x07, 0x0F, 0x1F, 0x3F, 0xFF, 0xFF, 0xFF, 0xFE, 0xFC, 0xF0, 0xE0, 0x00, 0x00,
  541.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01,
  542.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  543.     0x00, 0x00, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  544.     0x00, 0x00, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
  545.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xFF, 0xFF, 0xFF,
  546.     0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07,
  547.     0x0F, 0x1F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFE, 0xFC, 0xFC, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8, 0xF8,
  548.     0xFC, 0xFC, 0x7E, 0x7F, 0x3F, 0x1F, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x00, 0x00,
  549.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  550.     0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF0,
  551.     0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  552.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0xE0,
  553.     0xE0, 0xF0, 0xF0, 0xF8, 0xF8, 0xFC, 0xFE, 0xFF, 0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x03, 0x00, 0x00,
  554.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  555.     0x00, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x03, 0x03, 0x01,
  556.     0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // 9
  557. };
  558.  
  559. void ssd1306_draw_font(uint8_t x, uint8_t y, const char *ch, size_t ch_sz)
  560. {
  561.     size_t tt = 0;
  562.     uint8_t x_pos = x;
  563.     uint8_t y_pos = 0;
  564.  
  565.     for(tt=0; tt<ch_sz; ++tt)
  566.     {
  567.         if (x_pos >= (x + FONT_WIDTH))
  568.         {
  569.             x_pos = x;
  570.             y_pos += 1;
  571.         }
  572.  
  573.         ssd1306_write(CMD, Set_Page_Start_Address_CMD + y_pos);        // set row
  574.         ssd1306_write(CMD, SSD1306_SETLOWCOLUMN | (x_pos & 0xf));      // set lower column address
  575.         ssd1306_write(CMD, SSD1306_SETHIGHCOLUMN | (x_pos >> 4));      // set higher column address
  576.  
  577.         ssd1306_write(DAT, (uint8_t)ch[tt]);
  578.         x_pos += 1;
  579.     }
  580. }
  581.  
  582. void ssd1306_fill(uint8_t bmp_data)
  583. {                                                    
  584.     uint8_t x_pos = 0;
  585.     uint8_t page = 0;
  586.  
  587.     for (page=0; page < y_max; ++page)
  588.     {
  589.         ssd1306_write(CMD, (Set_Page_Start_Address_CMD + page));
  590.         ssd1306_write(CMD, SSD1306_SETLOWCOLUMN);
  591.         ssd1306_write(CMD, SSD1306_SETHIGHCOLUMN);
  592.  
  593.         for (x_pos=0; x_pos < SSD1306_LCDWIDTH; ++x_pos)
  594.         {
  595.             ssd1306_write(DAT, bmp_data);
  596.         }                                                                                  
  597.     }  
  598. }
  599.  
  600. void draw_tempere(unsigned short temp)
  601. {
  602.     if (temp == 0)
  603.     {
  604.         ssd1306_draw_font(0, 0, font_bitmap[0], sizeof(font_bitmap[0]));
  605.         ssd1306_draw_font(FONT_WIDTH, 0, font_bitmap[0], sizeof(font_bitmap[0]));
  606.         ssd1306_draw_font(2*FONT_WIDTH, 0, font_bitmap[0], sizeof(font_bitmap[0]));
  607.     }
  608.     else if (temp > 0 && temp < 10)
  609.     {
  610.         ssd1306_draw_font(0, 0, font_bitmap[0], sizeof(font_bitmap[0]));
  611.         ssd1306_draw_font(FONT_WIDTH, 0, font_bitmap[0], sizeof(font_bitmap[0]));
  612.         ssd1306_draw_font(2*FONT_WIDTH, 0, font_bitmap[temp], sizeof(font_bitmap[temp]));
  613.     }
  614.     else if (temp >= 10 && temp < 100)
  615.     {
  616.         ssd1306_draw_font(0, 0, font_bitmap[0], sizeof(font_bitmap[0]));
  617.         ssd1306_draw_font(FONT_WIDTH, 0, font_bitmap[(temp/10)%10], sizeof(font_bitmap[(temp/10)%10]));
  618.         ssd1306_draw_font(2*FONT_WIDTH, 0, font_bitmap[temp%10], sizeof(font_bitmap[temp%10]));
  619.     }
  620.     else if (temp >= 100 && temp < 1000)
  621.     {
  622.         ssd1306_draw_font(0, 0, font_bitmap[(temp/100)%10], sizeof(font_bitmap[(temp/100)%10]));
  623.         ssd1306_draw_font(FONT_WIDTH, 0, font_bitmap[(temp/10)%10], sizeof(font_bitmap[(temp/10)%10]));
  624.         ssd1306_draw_font(2*FONT_WIDTH, 0, font_bitmap[temp%10], sizeof(font_bitmap[temp%10]));
  625.     }
  626.     else
  627.     {
  628.         ssd1306_draw_font(0, 0, font_bitmap[9], sizeof(font_bitmap[9]));
  629.         ssd1306_draw_font(FONT_WIDTH, 0, font_bitmap[9], sizeof(font_bitmap[9]));
  630.         ssd1306_draw_font(2*FONT_WIDTH, 0, font_bitmap[9], sizeof(font_bitmap[9]));
  631.     }
  632. }
  633.  
  634. ///////////////////////////////////////////////////////////////////////////////////////////////
  635.  
  636. int main(int argc, char *argv[])
  637. {
  638.     if (!map_peripheral(&gpio)) {
  639.         printf("Failed to map the physical GPIO registers into the virtual memory space.\n");
  640.         return -1;
  641.     }
  642.  
  643.     if (!map_peripheral(&bsc0)) {
  644.         printf("Failed to map the physical BSC0 (I2C) registers into the virtual memory space.\n");
  645.         unmap_peripheral(&gpio);
  646.         return -1;
  647.     }
  648.  
  649.     if (!map_peripheral(&syst)) {
  650.         printf("Failed to map the physical SYST registers into the virtual memory space.\n");
  651.         unmap_peripheral(&gpio);
  652.         unmap_peripheral(&bsc0);
  653.         return -1;
  654.     }
  655.  
  656.     i2c_init();
  657.  
  658.     // Initialize the SSD1306 OLED with an I2C addr = 0x3c (default address)
  659.     BSC0_A = SSD1306_I2C_ADDRESS;
  660.  
  661.     ssd1306_init();
  662.  
  663.     // clear the display
  664.     ssd1306_fill(0x00);
  665.  
  666.     draw_tempere(260);
  667.  
  668.     // unmap gpio and bsc0
  669.     unmap_peripheral(&gpio);
  670.     unmap_peripheral(&bsc0);
  671.     unmap_peripheral(&syst);
  672.    
  673.     return 0;
  674. }
  675.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement