![](/media/cache/profiles/3764fbc78735e8f0e1d9bedfbc9b9488.jpg.50x50_q85.png)
IJFW - IchigoJamのBASICプログラムをメモリカード(MMCまたは互換カード)に保存したり読み出したりできるプログラム。メモリカードにファームウェアのファイルを置くだけで、電源ON時に自動的に書き換える機能も搭載(一応こちらがメイン)。LPC1114FN28専用。
main.cpp
00001 #include "mbed.h" 00002 #include "FatfsIjfwConfigurable.h" 00003 #include "UartIsp.h" 00004 #include "I2CSlave2.h" 00005 #include "I2c2mem.h" 00006 00007 // Pin definitions 00008 DigitalOut ledPow(dp13); // Power indicator 00009 DigitalOut ledCard(dp14); // Memory card access indicator 00010 00011 DigitalOut resetIJ(dp25); // IchigoJam Reset Pin 00012 DigitalOut ispIJ(dp26); // IchigoJam ISP Pin 00013 RawSerial serial(dp16, dp15); // tx, rx 00014 I2CSlave2 i2cs(dp5, dp27); // sda, scl 00015 00016 SPI spi(dp2, dp1, dp6); // SPI for memory card access (mosi, miso, sck) 00017 DigitalOut cs(dp4); // Memory card cs pin 00018 FatfsIjfwConfigurable fsij(&spi, &cs); // Fatfs for Memory card 00019 00020 00021 // file name 00022 const char* CONFIG_FILE = "_config.txt"; 00023 const char* BINFILE = "jam.bin"; 00024 00025 00026 void error() { 00027 while(1) { 00028 ledCard = 1; ledPow = 1; 00029 wait(0.25); 00030 ledCard = 0; ledPow = 0; 00031 wait(0.25); 00032 } 00033 } 00034 00035 00036 int main() { 00037 // LED 00038 ledPow = 1; ledCard = 0; 00039 00040 // Serial 00041 serial.baud(115200); 00042 00043 // Read Config File 00044 ledCard = 1; 00045 fsij.readConfigFile(CONFIG_FILE); 00046 ledCard = 0; 00047 00048 // Firmware update if bin file is found 00049 ledCard = 1; 00050 if (fsij.checkFirmFile(BINFILE)) { 00051 // Sequence of Entering UartISP mode 00052 ispIJ = 0; resetIJ = 0; // ISP=L, Reset=L 00053 wait_ms(100); 00054 ispIJ = 0; resetIJ = 1; // ISP=L, Reset=H 00055 wait_ms(100); 00056 ispIJ = 1; resetIJ = 1; // ISP=H, Reset=H 00057 wait_ms(100); 00058 00059 UartIsp uartisp(&serial, &fsij); // UartISP 00060 UartIsp::ISP_RESULT ret = uartisp.runUartIsp(BINFILE); // Run UartISP process 00061 if (ret != UartIsp::NOERROR) { 00062 error(); 00063 } 00064 00065 // reset MCU 00066 ispIJ = 1; resetIJ = 0; // ISP=H, Reset=L 00067 wait_ms(100); 00068 ispIJ = 1; resetIJ = 1; // ISP=H, Reset=H 00069 wait_ms(100); 00070 00071 // reset IJFW 00072 //NVIC_SystemReset(); 00073 } 00074 ledCard = 0; 00075 00076 // Data conversion I2C to/from memory card 00077 // address 0xA? -> EEPROM Emulation 00078 // 0x22 -> Writing/Reading data of the specific file 00079 // 0x24 -> Continuous writing mode 00080 I2c2mem i2c2m(&i2cs, &fsij, &ledCard); 00081 i2cs.address(0xA0, 0x8E); // Slave address, mask 00082 00083 while(1) { 00084 int rcv = i2cs.receive(); 00085 int addr = i2cs.addressFromMaster(); 00086 00087 switch (rcv) { 00088 case I2CSlave2::WriteAddressed: 00089 if (addr == 0xA0) { 00090 i2c2m.writeProgram(0); 00091 } else if (addr == 0xA8) { 00092 i2c2m.writeProgram(1); 00093 } else if (addr == 0x22) { // I2C address #11 in IchigoJam 00094 i2c2m.writeData(); 00095 } else if (addr == 0x24) { // I2C address #12 in IchigoJam 00096 i2c2m.writeDataContinuous(); 00097 } else { 00098 i2cs.stop(); 00099 } 00100 break; 00101 case I2CSlave2::ReadAddressed: 00102 if (addr == 0xA1) { 00103 i2c2m.readProgram(); 00104 } else if (addr == 0xA9) { 00105 i2c2m.readProgram(); 00106 } else if (addr == 0x23) { // I2C address #11 in IchigoJam 00107 i2c2m.readData(); 00108 } else if (addr == 0x25) { // I2C address #12 in IchigoJam 00109 i2c2m.reset(); 00110 } else { 00111 i2cs.stop(); 00112 } 00113 break; 00114 case I2CSlave2::WriteGeneral: 00115 i2cs.stop(); 00116 break; 00117 default: 00118 break; 00119 } 00120 00121 } 00122 }
Generated on Sat Jul 16 2022 19:47:26 by
![doxygen](doxygen.png)