Subversion Repositories HomeAutomation

Rev

Rev 679 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. #include <inttypes.h>
  2. #include <avr/interrupt.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <config.h> // All configuration parameters
  6. #include <bios.h>   // BIOS interface declarations, including CAN structure and ID defines.
  7. #include <drivers/timer/timer.h>
  8.  
  9. #include <drivers/lcd/glcd/ks0108.h>
  10. #include <drivers/lcd/glcd/font.h>
  11.  
  12. #include <avr/pgmspace.h>
  13.  
  14. #define APP_TYPE    0xf001
  15. #define APP_VERSION 0x0002
  16.  
  17.  
  18.  
  19.  
  20. /* Left half of the LCD */
  21.  
  22. static unsigned char Splash_left[] PROGMEM = {
  23.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x7F,
  24.         0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0xFF,0xFF,
  25.         0xFF,0xFF,0x7F,0x7F,0x3F,0xBF,0x3F,0x1F,
  26.         0x3F,0x3F,0x3F,0x7F,0xFF,0xBF,0x1F,0x47,
  27.         0x87,0x07,0x07,0x07,0x27,0x77,0x77,0x67,
  28.         0xE7,0xE7,0xE7,0xC7,0x87,0x07,0x07,0x07,
  29.         0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x87,
  30.         0xC7,0xF7,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  31.         0xFF,0xFF,0xFF,0xFF,0xFF,0xEF,0xEF,0x7F,
  32.         0x7F,0x7F,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,
  33.         0xFF,0xFF,0xFF,0xBF,0xFF,0xFF,0xFF,0xFF,
  34.         0x3F,0x7F,0x7F,0x7F,0x3F,0x3F,0x3F,0x1F,
  35.         0x1F,0x1F,0x1F,0x1F,0x0F,0x1F,0x1F,0x1F,
  36.         0x3F,0x3F,0x3F,0x3F,0x3F,0x7F,0x7F,0x7F,
  37.         0x7F,0x3F,0x3F,0x7F,0x7F,0x7F,0x7F,0x7F,
  38.         0x7F,0xFF,0xFF,0xFF,0x7F,0x7F,0xFF,0xFF,
  39.         0xFE,0xFE,0xFE,0xFF,0xFF,0xFF,0xF8,0xF8,
  40.         0xF0,0xF0,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,
  41.         0xF0,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,
  42.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,
  43.         0x0C,0x0E,0x1C,0x3F,0x0F,0x03,0x00,0x04,
  44.         0x04,0x87,0xCF,0x9F,0xFF,0xFE,0xFC,0xF8,
  45.         0xF8,0xFC,0xFE,0xFE,0xFF,0xFF,0xFF,0xFF,
  46.         0xFF,0xFD,0xFF,0xFF,0xFF,0xDF,0xCF,0x1F,
  47.         0x3F,0x3F,0x13,0x03,0x01,0x10,0x1C,0x0C,
  48.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  49.         0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00,
  50.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  51.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  52.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  53.         0x00,0x90,0xF8,0xF8,0xF8,0xF8,0xF8,0xCC,
  54.         0xE0,0xF0,0xF8,0xF8,0xF8,0xFC,0xFC,0xFE,
  55.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  56.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  57.         0xFF,0xFF,0xFF,0xFF,0xF8,0xF0,0xE0,0xE0,
  58.         0xC0,0x80,0x00,0x00,0x00,0x80,0xC0,0xC0,
  59.         0xE0,0xE0,0xC0,0xE0,0xF0,0xFC,0xFE,0xFE,
  60.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  61.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  62.         0xFF,0xFF,0xFF,0x3F,0x1F,0x09,0x01,0x00,
  63.         0x04,0x06,0x06,0x06,0x0E,0x1C,0x1E,0x18,
  64.         0x1C,0x18,0x19,0x19,0x01,0x03,0x00,0x00,
  65.         0x00,0x07,0x46,0x00,0x00,0x80,0x80,0x80,
  66.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  67.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68.         0x00,0x00,0x84,0xFC,0xF8,0xF4,0xFE,0xFE,
  69.         0xF7,0xFB,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,
  70.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  71.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  72.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  73.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  74.         0xFF,0xFF,0xFF,0xFC,0xFC,0xFC,0xFD,0xF9,
  75.         0xF9,0xF3,0xFF,0xFF,0x5F,0x0F,0x0F,0x0F,
  76.         0x0F,0x0F,0x1F,0x3F,0x3F,0x3F,0xFF,0xFF,
  77.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  78.         0xFF,0xFF,0xF0,0xE0,0xC0,0xC0,0xC0,0xC0,
  79.         0xC0,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,
  80.         0x00,0x00,0x00,0x00,0x00,0x03,0x06,0x00,
  81.         0x88,0xC8,0xFC,0xFC,0xFE,0xFF,0xFF,0xFF,
  82.         0xFF,0xFE,0xF0,0xE0,0xF8,0xFC,0xFE,0xFF,
  83.         0xFE,0xFC,0xF8,0x30,0x30,0xE0,0xF6,0x7F,
  84.         0x3F,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  85.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  86.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  87.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  88.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  89.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  90.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  91.         0xFF,0xFF,0xFF,0xFD,0xF0,0xE0,0xC0,0x00,
  92.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  93.         0x01,0x01,0xF1,0xFB,0xFF,0xFF,0xFF,0xFF,
  94.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  95.         0xFF,0xFF,0xFF,0xFE,0x98,0x00,0x00,0x00,
  96.         0x00,0x00,0x00,0x00,0x80,0xC0,0xFE,0x7F,
  97.         0x1F,0xDF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  98.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  99.         0xFF,0xFF,0xFF,0xFE,0xFC,0xFF,0xFF,0xFE,
  100.         0xFE,0x7F,0x7E,0x3F,0x1F,0x1F,0x0F,0x0F,
  101.         0x3D,0x39,0x19,0x3B,0x7F,0xFF,0xFF,0xFF,
  102.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  103.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  104.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  105.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  106.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  107.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,
  108.         0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0xFE,
  109.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  110.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  111.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0xF0,0xF0,
  112.         0xF0,0xF0,0xF8,0xFC,0xFF,0xFF,0xFF,0xFF,
  113.         0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  114.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  115.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  116.         0xFC,0xF0,0xF0,0xF0,0xF8,0xF8,0xF8,0xF0,
  117.         0xF0,0xE0,0xC0,0xC0,0xE0,0xF0,0xFF,0xFF,
  118.         0xFF,0xFF,0xFF,0xFF,0x7F,0xFF,0xDF,0xFF,
  119.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  120.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  121.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  122.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  123.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0xF8,
  124.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  125.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  126.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  127.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  128.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  129.         0xFF,0x7F,0x7F,0x7F,0xFF,0xFF,0xFF,0xFF,
  130.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x7F,
  131.         0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,
  132.         0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,
  133.         0x7F,0x7F,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,
  134.         0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  135.         0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,
  136.         0x07,0x07,0x07,0x07,0x07,0x07,0x03,0x03,
  137.         0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
  138.         0x03,0x03,0x03,0x03,0x03,0x01,0x03,0x03,
  139.         0x03,0x03,0x03,0x03,0x03,0x01,0x01,0x00,
  140.         0x00,0x00,0x07,0x07,0x07,0x07,0x07,0x07,
  141.         0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,
  142.         0x07,0x03,0x03,0x01,0x01,0x01,0x01,0x01,
  143.         0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  144.         0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,
  145.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  146.         0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
  147.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  148.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  149.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  150.         0x00,0x01,0x05,0x05,0x07,0x07,0x07,0x07
  151.          };
  152.  
  153. uint16_t ixa = 0;
  154. uint8_t jxa = 0;
  155.  
  156.  
  157. // A simple message "queue", with space for one message only.
  158. // These are declared volatile to tell the compiler not to optimize away accesses.
  159. volatile Can_Message_t rxMsg; // Message storage
  160. volatile uint8_t rxMsgFull;   // Synchronization flag
  161.  
  162. // CAN message reception callback.
  163. // This function runs with interrupts disabled, keep it as short as possible.
  164. void can_receive(Can_Message_t *msg) {
  165.     if (!rxMsgFull) {
  166.         memcpy((void*)&rxMsg, msg, sizeof(rxMsg));
  167.         rxMsgFull = 1;
  168.     }
  169. }
  170.  
  171. // Timer callback function used for some timer tests
  172. void timer_callback(uint8_t timer) {
  173.     Can_Message_t msg;
  174.    
  175.     msg.ExtendedFlag = 1;
  176.     msg.Id = (CAN_TST << CAN_SHIFT_CLASS) | NODE_ID;
  177.     msg.RemoteFlag = 0;
  178.     msg.DataLength = 1;
  179.     msg.Data.bytes[0] = timer;
  180.    
  181.     BIOS_CanSend(&msg);
  182. }
  183.  
  184. int main(void)
  185. {
  186.    
  187.    
  188.    
  189.    
  190.     //Initiera utgŒngar
  191.  
  192.     DDRB |= (1<<7)|(1<<2)|(1<<1)|(1<<0);
  193.    
  194.  
  195.     DDRC |= (1<<5)|(1<<4);
  196.    
  197.  
  198.     DDRD |= (1<<7)|(1<<6)|(1<<5)|(1<<4)|(1<<2)|(1<<1)|(1<<0);
  199.    
  200.    
  201.     // Enable interrupts as early as possible
  202.     sei();
  203.    
  204.     unsigned long time;
  205.    
  206.     Can_Message_t txMsg;
  207.     txMsg.Id = (CAN_NMT_APP_START << CAN_SHIFT_NMT_TYPE) | (NODE_ID << CAN_SHIFT_NMT_SID);
  208.     txMsg.DataLength = 4;
  209.     txMsg.RemoteFlag = 0;
  210.     txMsg.ExtendedFlag = 1;
  211.     txMsg.Data.words[0] = APP_TYPE;
  212.     txMsg.Data.words[1] = APP_VERSION;
  213.    
  214.     // Set up callback for CAN reception, this is optional if only sending is required.
  215.     BIOS_CanCallback = &can_receive;
  216.     // Send CAN_NMT_APP_START
  217.     BIOS_CanSend(&txMsg);
  218.    
  219.  
  220.  
  221.     /* Kukgrejer frŒn apetech-libbet
  222.     // Wait a little while the display starts up
  223.     for(volatile uint16_t i=0; i<15000; i++);
  224.    
  225.     // Initialize the LCD
  226.     ks0108Init(0);
  227.    
  228.     // Select a font
  229.     ks0108SelectFont(Arial_Bold_14, ks0108ReadFontData, BLACK);
  230.     // Set a position
  231.     ks0108GotoXY(15,10);
  232.     // Print some text
  233.     ks0108Puts_P(PSTR("KS0108-Treiber"));
  234.     // a nice little round rect
  235.     ks0108DrawRoundRect(5, 5, 117, 20, 8, BLACK);
  236.  
  237.     // Once again :)
  238.     // Select a font
  239.     ks0108SelectFont(Corsiva_12, ks0108ReadFontData, BLACK);
  240.     // Set a position
  241.     ks0108GotoXY(5,0);
  242.     // Print some text
  243.     ks0108Puts_P(PSTR("http://www.apetech.de\nmailto:me@apetech.de"));
  244.  
  245.     */
  246.    
  247.    
  248.    
  249.    
  250.     glcdPowerOn();
  251.  
  252.     glcdSetXY(0,0);
  253.  
  254.     //glcdPutStr("This is a test....... Let us try another row.. And another.. And some more..");
  255.  
  256.     for (jxa = 0; jxa< 8; jxa++){
  257.         glcdSetXY(0,jxa);
  258.         for (ixa = 0; ixa < 128; ixa++){
  259.             glcdWriteData(pgm_read_byte((uint16_t)&Splash_left+ixa+jxa*128));
  260.         }
  261.     }
  262.     glcdSetXY(0,0);
  263.     glcdPutStr("I can write text. This is cool. Yeah baby! Pixelina!");
  264.    
  265.     /*glcdSetXY(5,5);
  266.     glcdPutStr("I can write text.");
  267.     glcdSetXY(8,10);
  268.     glcdPutStr("Everywhere!");
  269.     */
  270.    
  271.     while (1) {
  272.         //glcdSetXY(0,0);
  273.         //glcdPutStr("This is a test.... Let us try another row.. And another.. And some more..");
  274.  
  275.        
  276.         if (Timer_Expired(0)) {
  277.             // Send a CAN message
  278.             time = Timer_GetTicks();
  279.             txMsg.Data.dwords[1] = time;
  280.             BIOS_CanSend(&txMsg);
  281.             //printf("Two seconds passed, time is now %ld.\n", time);
  282.         }
  283.        
  284.         if (rxMsgFull) {
  285.             // Print the received message
  286. /*          printf("RX: ID=%08lx, DLC=%u, EXT=%u, RTR=%u, data={ ",
  287.                     rxMsg.Id,
  288.                     (uint16_t)rxMsg.DataLength,
  289.                     (uint16_t)rxMsg.ExtendedFlag,
  290.                     (uint16_t)rxMsg.RemoteFlag);
  291.             for (uint8_t i=0; i<rxMsg.DataLength; i++) {
  292.                 printf("%02x ", rxMsg.Data.bytes[i]);
  293.             }
  294.             printf("}\n");*/
  295.             rxMsgFull = 0; //  
  296.         }
  297.     }
  298.    
  299.     return 0;
  300. }
  301.