Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: I2Cdev_MAX32630FTHR
Adafruit_IS31FL3731.cpp
00001 #include "Adafruit_IS31FL3731.h" 00002 #include "Adafruit_GFX.h" 00003 #ifndef _swap_int16_t 00004 #define _swap_int16_t(a, b) { int16_t t = a; a = b; b = t; } 00005 #endif 00006 00007 bool Adafruit_IS31FL3731::begin(uint8_t addr) { 00008 00009 _i2caddr = addr; 00010 _frame = 0; 00011 00012 // shutdown 00013 writeRegister8(ISSI_BANK_FUNCTIONREG, ISSI_REG_SHUTDOWN, 0x00); 00014 00015 //delay(10); 00016 wait(0.01); 00017 00018 00019 // out of shutdown 00020 writeRegister8(ISSI_BANK_FUNCTIONREG, ISSI_REG_SHUTDOWN, 0x01); 00021 00022 // picture mode 00023 writeRegister8(ISSI_BANK_FUNCTIONREG, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE); 00024 00025 displayFrame(_frame); 00026 00027 // all LEDs on & 0 PWM 00028 clear(); // set each led to 0 PWM 00029 00030 for (uint8_t f=0; f<8; f++) { 00031 for (uint8_t i=0; i<=0x11; i++) 00032 writeRegister8(f, i, 0xff); // each 8 LEDs on 00033 } 00034 00035 audioSync(false); 00036 00037 return true; 00038 } 00039 00040 void Adafruit_IS31FL3731::clear(void) { 00041 // all LEDs on & 0 PWM 00042 00043 selectBank(_frame); 00044 00045 uint8_t nemo[24] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 00046 00047 for (uint8_t i=0; i<6; i++) { 00048 // write 24 bytes at once 00049 myI2C->writeBytes(_i2caddr, 0x24+i*24, 24, nemo); 00050 } 00051 } 00052 00053 void Adafruit_IS31FL3731::setLEDPWM(uint8_t lednum, uint8_t pwm, uint8_t bank) { 00054 if (lednum >= 144) return; 00055 writeRegister8(bank, 0x24+lednum, pwm); 00056 } 00057 00058 00059 void Adafruit_IS31FL3731_Wing::drawPixel(int16_t x, int16_t y, uint16_t color) { 00060 switch (getRotation()) { 00061 case 1: 00062 _swap_int16_t(x, y); 00063 x = 15 - x - 1; 00064 break; 00065 case 2: 00066 x = 15 - x - 1; 00067 y = 7 - y - 1; 00068 break; 00069 case 3: 00070 _swap_int16_t(x, y); 00071 y = 9 - y - 1; 00072 break; 00073 } 00074 00075 // charlie wing is smaller: 00076 if ((x < 0) || (x >= 16) || (y < 0) || (y >= 7)) return; 00077 00078 if (x > 7) { 00079 x=15-x; 00080 y += 8; 00081 } else { 00082 y = 7-y; 00083 } 00084 00085 _swap_int16_t(x, y); 00086 00087 if (color > 255) color = 255; // PWM 8bit max 00088 00089 setLEDPWM(x + y*16, color, _frame); 00090 return; 00091 } 00092 00093 00094 00095 void Adafruit_IS31FL3731::drawPixel(int16_t x, int16_t y, uint16_t color) { 00096 // check rotation, move pixel around if necessary 00097 switch (getRotation()) { 00098 case 1: 00099 _swap_int16_t(x, y); 00100 x = 16 - x - 1; 00101 break; 00102 case 2: 00103 x = 16 - x - 1; 00104 y = 9 - y - 1; 00105 break; 00106 case 3: 00107 _swap_int16_t(x, y); 00108 y = 9 - y - 1; 00109 break; 00110 } 00111 00112 if ((x < 0) || (x >= 16)) return; 00113 if ((y < 0) || (y >= 9)) return; 00114 if (color > 255) color = 255; // PWM 8bit max 00115 00116 setLEDPWM(x + y*16, color, _frame); 00117 return; 00118 } 00119 00120 void Adafruit_IS31FL3731::setFrame(uint8_t f) { 00121 _frame = f; 00122 } 00123 00124 void Adafruit_IS31FL3731::displayFrame(uint8_t f) { 00125 if (f > 7) f = 0; 00126 writeRegister8(ISSI_BANK_FUNCTIONREG, ISSI_REG_PICTUREFRAME, f); 00127 } 00128 00129 00130 void Adafruit_IS31FL3731::selectBank(uint8_t b) { 00131 myI2C->writeByte(_i2caddr, ISSI_COMMANDREGISTER, b); 00132 } 00133 00134 void Adafruit_IS31FL3731::audioSync(bool sync) { 00135 if (sync) { 00136 writeRegister8(ISSI_BANK_FUNCTIONREG, ISSI_REG_AUDIOSYNC, 0x1); 00137 } else { 00138 writeRegister8(ISSI_BANK_FUNCTIONREG, ISSI_REG_AUDIOSYNC, 0x0); 00139 } 00140 } 00141 00142 /*************/ 00143 void Adafruit_IS31FL3731::writeRegister8(uint8_t b, uint8_t reg, uint8_t data) { 00144 selectBank(b); 00145 00146 myI2C->writeByte(_i2caddr, reg, data); 00147 } 00148 00149 uint8_t Adafruit_IS31FL3731::readRegister8(uint8_t bank, uint8_t reg) { 00150 uint8_t x; 00151 //uint8_t status; 00152 00153 selectBank(bank); 00154 00155 //status = 00156 myI2C->readByte(_i2caddr, reg, &x); 00157 00158 return x; 00159 }
Generated on Mon Jul 18 2022 17:51:09 by
1.7.2