Merge pull request #53 from zsa/driver/3733_enhancement

ISSI 3733 Driver Enhancement
pull/5990/head
Florian Didron 6 years ago committed by GitHub
commit 20218bebf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -75,10 +75,10 @@ uint8_t g_twi_transfer_buffer[20];
// buffers and the transfers in IS31FL3733_write_pwm_buffer() but it's // buffers and the transfers in IS31FL3733_write_pwm_buffer() but it's
// probably not worth the extra complexity. // probably not worth the extra complexity.
uint8_t g_pwm_buffer[DRIVER_COUNT][192]; uint8_t g_pwm_buffer[DRIVER_COUNT][192];
bool g_pwm_buffer_update_required = false; bool g_pwm_buffer_update_required[DRIVER_COUNT] = { false };
uint8_t g_led_control_registers[DRIVER_COUNT][24] = { { 0 }, { 0 } }; uint8_t g_led_control_registers[DRIVER_COUNT][24] = { { 0 }, { 0 } };
bool g_led_control_registers_update_required = false; bool g_led_control_registers_update_required[DRIVER_COUNT] = { false };
void IS31FL3733_write_register( uint8_t addr, uint8_t reg, uint8_t data ) void IS31FL3733_write_register( uint8_t addr, uint8_t reg, uint8_t data )
{ {
@ -123,12 +123,13 @@ void IS31FL3733_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer )
} }
} }
void IS31FL3733_init( uint8_t addr ) void IS31FL3733_init( uint8_t addr, uint8_t sync)
{ {
// In order to avoid the LEDs being driven with garbage data // In order to avoid the LEDs being driven with garbage data
// in the LED driver's PWM registers, shutdown is enabled last. // in the LED driver's PWM registers, shutdown is enabled last.
// Set up the mode and other settings, clear the PWM registers, // Set up the mode and other settings, clear the PWM registers,
// then disable software shutdown. // then disable software shutdown.
// Sync is passed so set it according to the datasheet.
// Unlock the command register. // Unlock the command register.
IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 ); IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 );
@ -161,7 +162,7 @@ void IS31FL3733_init( uint8_t addr )
// Set global current to maximum. // Set global current to maximum.
IS31FL3733_write_register( addr, ISSI_REG_GLOBALCURRENT, 0xFF ); IS31FL3733_write_register( addr, ISSI_REG_GLOBALCURRENT, 0xFF );
// Disable software shutdown. // Disable software shutdown.
IS31FL3733_write_register( addr, ISSI_REG_CONFIGURATION, 0x01 ); IS31FL3733_write_register( addr, ISSI_REG_CONFIGURATION, (sync << 6) | 0x01 );
// Wait 10ms to ensure the device has woken up. // Wait 10ms to ensure the device has woken up.
#ifdef __AVR__ #ifdef __AVR__
@ -179,7 +180,7 @@ void IS31FL3733_set_color( int index, uint8_t red, uint8_t green, uint8_t blue )
g_pwm_buffer[led.driver][led.r] = red; g_pwm_buffer[led.driver][led.r] = red;
g_pwm_buffer[led.driver][led.g] = green; g_pwm_buffer[led.driver][led.g] = green;
g_pwm_buffer[led.driver][led.b] = blue; g_pwm_buffer[led.driver][led.b] = blue;
g_pwm_buffer_update_required = true; g_pwm_buffer_update_required[led.driver] = true;
} }
} }
@ -218,35 +219,34 @@ void IS31FL3733_set_led_control_register( uint8_t index, bool red, bool green, b
g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b); g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
} }
g_led_control_registers_update_required = true; g_led_control_registers_update_required[led.driver] = true;
} }
void IS31FL3733_update_pwm_buffers( uint8_t addr1, uint8_t addr2 ) void IS31FL3733_update_pwm_buffers( uint8_t addr, uint8_t index )
{ {
if ( g_pwm_buffer_update_required ) if ( g_pwm_buffer_update_required[index] )
{ {
// Firstly we need to unlock the command register and select PG1 // Firstly we need to unlock the command register and select PG1
IS31FL3733_write_register( addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 ); IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 );
IS31FL3733_write_register( addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM ); IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM );
IS31FL3733_write_pwm_buffer( addr1, g_pwm_buffer[0] ); IS31FL3733_write_pwm_buffer( addr, g_pwm_buffer[index] );
//IS31FL3733_write_pwm_buffer( addr2, g_pwm_buffer[1] );
} }
g_pwm_buffer_update_required = false; g_pwm_buffer_update_required[index] = false;
} }
void IS31FL3733_update_led_control_registers( uint8_t addr1, uint8_t addr2 ) void IS31FL3733_update_led_control_registers( uint8_t addr, uint8_t index )
{ {
if ( g_led_control_registers_update_required ) if ( g_led_control_registers_update_required[index] )
{ {
// Firstly we need to unlock the command register and select PG0 // Firstly we need to unlock the command register and select PG0
IS31FL3733_write_register( addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 ); IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5 );
IS31FL3733_write_register( addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL ); IS31FL3733_write_register( addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL );
for ( int i=0; i<24; i++ ) for ( int i=0; i<24; i++ )
{ {
IS31FL3733_write_register(addr1, i, g_led_control_registers[0][i] ); IS31FL3733_write_register(addr, i, g_led_control_registers[index][i] );
//IS31FL3733_write_register(addr2, i, g_led_control_registers[1][i] );
} }
} }
g_led_control_registers_update_required[index] = false;
} }

@ -32,7 +32,7 @@ typedef struct is31_led {
extern const is31_led g_is31_leds[DRIVER_LED_TOTAL]; extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
void IS31FL3733_init( uint8_t addr ); void IS31FL3733_init( uint8_t addr, uint8_t sync );
void IS31FL3733_write_register( uint8_t addr, uint8_t reg, uint8_t data ); void IS31FL3733_write_register( uint8_t addr, uint8_t reg, uint8_t data );
void IS31FL3733_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer ); void IS31FL3733_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer );
@ -45,8 +45,8 @@ void IS31FL3733_set_led_control_register( uint8_t index, bool red, bool green, b
// (eg. from a timer interrupt). // (eg. from a timer interrupt).
// Call this while idle (in between matrix scans). // Call this while idle (in between matrix scans).
// If the buffer is dirty, it will update the driver with the buffer. // If the buffer is dirty, it will update the driver with the buffer.
void IS31FL3733_update_pwm_buffers( uint8_t addr1, uint8_t addr2 ); void IS31FL3733_update_pwm_buffers( uint8_t addr, uint8_t index );
void IS31FL3733_update_led_control_registers( uint8_t addr1, uint8_t addr2 ); void IS31FL3733_update_led_control_registers( uint8_t addr, uint8_t index );
#define A_1 0x00 #define A_1 0x00
#define A_2 0x01 #define A_2 0x01

@ -53,16 +53,16 @@ static void init(void) {
#endif #endif
#else #else
#ifdef LED_DRIVER_ADDR_1 #ifdef LED_DRIVER_ADDR_1
IS31FL3733_init(LED_DRIVER_ADDR_1); IS31FL3733_init(LED_DRIVER_ADDR_1, 0 );
#endif #endif
#ifdef LED_DRIVER_ADDR_2 #ifdef LED_DRIVER_ADDR_2
IS31FL3733_init(LED_DRIVER_ADDR_2); IS31FL3733_init(LED_DRIVER_ADDR_2, 0 );
#endif #endif
#ifdef LED_DRIVER_ADDR_3 #ifdef LED_DRIVER_ADDR_3
IS31FL3733_init(LED_DRIVER_ADDR_3); IS31FL3733_init(LED_DRIVER_ADDR_3, 0 );
#endif #endif
#ifdef LED_DRIVER_ADDR_4 #ifdef LED_DRIVER_ADDR_4
IS31FL3733_init(LED_DRIVER_ADDR_4); IS31FL3733_init(LED_DRIVER_ADDR_4, 0 );
#endif #endif
#endif #endif

@ -34,7 +34,7 @@ static void init( void )
IS31FL3731_init( DRIVER_ADDR_1 ); IS31FL3731_init( DRIVER_ADDR_1 );
IS31FL3731_init( DRIVER_ADDR_2 ); IS31FL3731_init( DRIVER_ADDR_2 );
#elif defined(IS31FL3733) #elif defined(IS31FL3733)
IS31FL3733_init( DRIVER_ADDR_1 ); IS31FL3733_init( DRIVER_ADDR_1, 0 );
#else #else
IS31FL3737_init( DRIVER_ADDR_1 ); IS31FL3737_init( DRIVER_ADDR_1 );
#endif #endif
@ -53,7 +53,8 @@ static void init( void )
#ifdef IS31FL3731 #ifdef IS31FL3731
IS31FL3731_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); IS31FL3731_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
#elif defined(IS31FL3733) #elif defined(IS31FL3733)
IS31FL3733_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); IS31FL3733_update_led_control_registers( DRIVER_ADDR_1, 0 );
IS31FL3733_update_led_control_registers( DRIVER_ADDR_2, 1 );
#else #else
IS31FL3737_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); IS31FL3737_update_led_control_registers( DRIVER_ADDR_1, DRIVER_ADDR_2 );
#endif #endif
@ -74,7 +75,8 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
#elif defined(IS31FL3733) #elif defined(IS31FL3733)
static void flush( void ) static void flush( void )
{ {
IS31FL3733_update_pwm_buffers( DRIVER_ADDR_1, DRIVER_ADDR_2 ); IS31FL3733_update_pwm_buffers( DRIVER_ADDR_1, 0);
IS31FL3733_update_pwm_buffers( DRIVER_ADDR_2, 1);
} }
const rgb_matrix_driver_t rgb_matrix_driver = { const rgb_matrix_driver_t rgb_matrix_driver = {

Loading…
Cancel
Save