Skip to content

Commit

Permalink
ISSI31FL3733 driver (qmk#3679)
Browse files Browse the repository at this point in the history
* ISSI31FL3733 driver

- Addapted IS31 driver for the above driver

* fix my branch

* ISSI31FL3733 driver

- Inclusion of above ISSI led driver

* IS31fl3733 driver

- Added correct function for control registers

* Finalized support for ISSI31fl3733 led driver

- Finalized and tested driver.
- Modified i2c_master for arm due to declaration mistake.
- Fixed spaces/tabs in quantum.h file.
- Fixed spaces/tabs in common_features.mk file.
- Removed unnecessary includes from rgb_matrix.c file.
- Added local definitions for MIN and MAX macros in rgb_matrix.c file.
- Adjusted chevron effect.
- Added necessary define (RGB_3733_MATRIX_ENABLE) for makefile.
- Added necessary C define (ISSI3733) to aid with inclusion of the correct header file.
- Added documentation for the new driver.

* Driver structure update

- Changed rule includes to be more condensed (RGB_MATRIX_ENABLE = IS31FL3731) and (RGB_MATRIX_ENABLE = IS31FL3733)
- Updated documentation
- Reverted to the use of differently named functions for each driver and selecting the needed ones within rgb_matrix.c

* ISSI Drivers refractoring

- Moved issi drivers in a dedicated folder
- Updated documentation

* I2C library fix

I released the special pins incorrectly before. It is now fixed.
  • Loading branch information
yiancar authored and Alexey Danilov committed Sep 6, 2018
1 parent 0dd07c3 commit 33af5f8
Show file tree
Hide file tree
Showing 12 changed files with 717 additions and 88 deletions.
40 changes: 32 additions & 8 deletions common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ endif

ifeq ($(strip $(STENO_ENABLE)), yes)
OPT_DEFS += -DSTENO_ENABLE
VIRTSER_ENABLE := yes
SRC += $(QUANTUM_DIR)/process_keycode/process_steno.c
VIRTSER_ENABLE := yes
SRC += $(QUANTUM_DIR)/process_keycode/process_steno.c
endif

ifeq ($(strip $(VIRTSER_ENABLE)), yes)
Expand All @@ -75,9 +75,9 @@ ifeq ($(strip $(FAUXCLICKY_ENABLE)), yes)
endif

ifeq ($(strip $(POINTING_DEVICE_ENABLE)), yes)
OPT_DEFS += -DPOINTING_DEVICE_ENABLE
OPT_DEFS += -DMOUSE_ENABLE
SRC += $(QUANTUM_DIR)/pointing_device.c
OPT_DEFS += -DPOINTING_DEVICE_ENABLE
OPT_DEFS += -DMOUSE_ENABLE
SRC += $(QUANTUM_DIR)/pointing_device.c
endif

ifeq ($(strip $(UCIS_ENABLE)), yes)
Expand Down Expand Up @@ -110,19 +110,43 @@ ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
ifeq ($(strip $(RGBLIGHT_CUSTOM_DRIVER)), yes)
OPT_DEFS += -DRGBLIGHT_CUSTOM_DRIVER
else
SRC += ws2812.c
SRC += ws2812.c
endif
endif

ifeq ($(strip $(RGB_MATRIX_ENABLE)), yes)
OPT_DEFS += -DRGB_MATRIX_ENABLE
OPT_DEFS += -DIS31FL3731
COMMON_VPATH += $(DRIVER_PATH)/issi
SRC += is31fl3731.c
SRC += i2c_master.c
SRC += $(QUANTUM_DIR)/color.c
SRC += $(QUANTUM_DIR)/rgb_matrix.c
CIE1931_CURVE = yes
endif

ifeq ($(strip $(RGB_MATRIX_ENABLE)), IS31FL3731)
OPT_DEFS += -DRGB_MATRIX_ENABLE
OPT_DEFS += -DIS31FL3731
COMMON_VPATH += $(DRIVER_PATH)/issi
SRC += is31fl3731.c
SRC += i2c_master.c
SRC += $(QUANTUM_DIR)/color.c
SRC += $(QUANTUM_DIR)/rgb_matrix.c
CIE1931_CURVE = yes
endif

ifeq ($(strip $(RGB_MATRIX_ENABLE)), IS31FL3733)
OPT_DEFS += -DRGB_MATRIX_ENABLE
OPT_DEFS += -DIS31FL3733
COMMON_VPATH += $(DRIVER_PATH)/issi
SRC += is31fl3733.c
SRC += i2c_master.c
SRC += $(QUANTUM_DIR)/color.c
SRC += $(QUANTUM_DIR)/rgb_matrix.c
CIE1931_CURVE = yes
endif

ifeq ($(strip $(TAP_DANCE_ENABLE)), yes)
OPT_DEFS += -DTAP_DANCE_ENABLE
SRC += $(QUANTUM_DIR)/process_keycode/process_tap_dance.c
Expand Down Expand Up @@ -169,7 +193,7 @@ ifeq ($(strip $(BACKLIGHT_ENABLE)), yes)
ifeq ($(strip $(VISUALIZER_ENABLE)), yes)
CIE1931_CURVE = yes
endif
ifeq ($(strip $(BACKLIGHT_CUSTOM_DRIVER)), yes)
ifeq ($(strip $(BACKLIGHT_CUSTOM_DRIVER)), yes)
OPT_DEFS += -DBACKLIGHT_CUSTOM_DRIVER
endif
endif
Expand Down Expand Up @@ -200,7 +224,7 @@ endif

ifeq ($(strip $(HD44780_ENABLE)), yes)
SRC += drivers/avr/hd44780.c
OPT_DEFS += -DHD44780_ENABLE
OPT_DEFS += -DHD44780_ENABLE
endif

QUANTUM_SRC:= \
Expand Down
52 changes: 50 additions & 2 deletions docs/feature_rgb_matrix.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# RGB Matrix Lighting

## Driver configuration

### IS31FL3731

There is basic support for addressable RGB matrix lighting with the I2C IS31FL3731 RGB controller. To enable it, add this to your `rules.mk`:

RGB_MATRIX_ENABLE = yes
RGB_MATRIX_ENABLE = IS31FL3731

Configure the hardware via your `config.h`:

Expand Down Expand Up @@ -36,7 +40,51 @@ Define these arrays listing all the LEDs in your `<keyboard>.c`:
....
}

Where `Cx_y` is the location of the LED in the matrix defined by [the datasheet](http://www.issi.com/WW/pdf/31FL3731.pdf). The `driver` is the index of the driver you defined in your `config.h` (`0` or `1` right now).
Where `Cx_y` is the location of the LED in the matrix defined by [the datasheet](http://www.issi.com/WW/pdf/31FL3731.pdf) and the header file `drivers/issi/is31fl3731.h`. The `driver` is the index of the driver you defined in your `config.h` (`0` or `1` right now).

### IS31FL3733

There is basic support for addressable RGB matrix lighting with the I2C IS31FL3733 RGB controller. To enable it, add this to your `rules.mk`:

RGB_MATRIX_ENABLE = IS31FL3733

Configure the hardware via your `config.h`:

// This is a 7-bit address, that gets left-shifted and bit 0
// set to 0 for write, 1 for read (as per I2C protocol)
// The address will vary depending on your wiring:
// 00 <-> GND
// 01 <-> SCL
// 10 <-> SDA
// 11 <-> VCC
// ADDR1 represents A1:A0 of the 7-bit address.
// ADDR2 represents A3:A2 of the 7-bit address.
// The result is: 0b101(ADDR2)(ADDR1)
#define DRIVER_ADDR_1 0b1010000
#define DRIVER_ADDR_2 0b1010000 // this is here for compliancy reasons.

#define DRIVER_COUNT 1
#define DRIVER_1_LED_TOTAL 64
#define DRIVER_LED_TOTAL DRIVER_1_LED_TOTAL

Currently only a single drivers is supported, but it would be trivial to support all 4 combinations. For now define `DRIVER_ADDR_2` as `DRIVER_ADDR_1`

Define these arrays listing all the LEDs in your `<keyboard>.c`:

const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
* | | G location
* | | | B location
* | | | | */
{0, B_1, A_1, C_1},
....
}

Where `X_Y` is the location of the LED in the matrix defined by [the datasheet](http://www.issi.com/WW/pdf/31FL3733.pdf) and the header file `drivers/issi/is31fl3733.h`. The `driver` is the index of the driver you defined in your `config.h` (Only `0` right now).

From this point forward the configuration is the same for all the drivers.

const rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = {
/* {row | col << 4}
Expand Down
6 changes: 5 additions & 1 deletion docs/hardware_drivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ You can make use of uGFX within QMK to drive character and graphic LCD's, LED ar

Support for WS2811/WS2812{a,b,c} LED's. For more information see the [RGB Light](feature_rgblight.md) page.

## IS31FL3731 (AVR Only)
## IS31FL3731

Support for up to 2 drivers. Each driver impliments 2 charlieplex matrices to individually address LEDs using I2C. This allows up to 144 same color LEDs or 32 RGB LEDs. For more information on how to setup the driver see the [RGB Matrix](feature_rgb_matrix.md) page.

## IS31FL3733

Support for up to a single driver with room for expansion. Each driver can control 192 individual LEDs or 64 RGB LEDs. For more information on how to setup the driver see the [RGB Matrix](feature_rgb_matrix.md) page.
13 changes: 7 additions & 6 deletions drivers/arm/i2c_master.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* This library follows the convention of the AVR i2c_master library.
/* This library is only valid for STM32 processors.
* This library follows the convention of the AVR i2c_master library.
* As a result addresses are expected to be already shifted (addr << 1).
* I2CD1 is the default driver which corresponds to pins B6 and B7. This
* can be changed.
* Please ensure that HAL_USE_I2C is TRUE in the halconf.h file and that
* STM32_I2C_USE_I2C1 is TRUE in the mcuconf.h file.
* STM32_I2C_USE_I2C1 is TRUE in the mcuconf.h file. Pins B6 and B7 are used
* but using any other I2C pins should be trivial.
*/

#include "i2c_master.h"
Expand All @@ -41,7 +43,7 @@ static const I2CConfig i2cconfig = {

void i2c_init(void)
{
palSetGroupMode(GPIOB,6,7, PAL_MODE_INPUT); // Try releasing special pins for a short time
palSetGroupMode(GPIOB, GPIOB_PIN6 | GPIOB_PIN7, 0, PAL_MODE_INPUT); // Try releasing special pins for a short time
chThdSleepMilliseconds(10);

palSetPadMode(GPIOB, 6, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUPDR_PULLUP);
Expand Down Expand Up @@ -82,12 +84,12 @@ uint8_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t l
{
complete_packet[i+1] = data[i];
}
complete_packet[0] = regaddr
complete_packet[0] = regaddr;

return i2cMasterTransmitTimeout(&I2C_DRIVER, (i2c_address >> 1), complete_packet, length + 1, 0, 0, MS2ST(timeout));
}

uint8_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout)
uint8_t i2c_readReg(uint8_t devaddr, uint8_t* regaddr, uint8_t* data, uint16_t length, uint16_t timeout)
{
i2c_address = devaddr;
i2cStart(&I2C_DRIVER, &i2cconfig);
Expand All @@ -97,7 +99,6 @@ uint8_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t le
// This is usually not needed. It releases the driver to allow pins to become GPIO again.
uint8_t i2c_stop(uint16_t timeout)
{
i2c_address = address;
i2cStop(&I2C_DRIVER);
return 0;
}
4 changes: 2 additions & 2 deletions drivers/arm/i2c_master.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ uint8_t i2c_start(uint8_t address);
uint8_t i2c_transmit(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout);
uint8_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout);
uint8_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
uint8_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
void i2c_stop(void);
uint8_t i2c_readReg(uint8_t devaddr, uint8_t* regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
uint8_t i2c_stop(uint16_t timeout);
50 changes: 25 additions & 25 deletions drivers/is31fl3731.c → drivers/issi/is31fl3731.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool g_led_control_registers_update_required = false;
// 0x10 - R16,R15,R14,R13,R12,R11,R10,R09


void IS31_write_register( uint8_t addr, uint8_t reg, uint8_t data )
void IS31FL3731_write_register( uint8_t addr, uint8_t reg, uint8_t data )
{
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
Expand All @@ -106,7 +106,7 @@ void IS31_write_register( uint8_t addr, uint8_t reg, uint8_t data )
#endif
}

void IS31_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer )
void IS31FL3731_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer )
{
// assumes bank is already selected

Expand Down Expand Up @@ -135,18 +135,18 @@ void IS31_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer )
}
}

void IS31_init( uint8_t addr )
void IS31FL3731_init( uint8_t addr )
{
// In order to avoid the LEDs being driven with garbage data
// in the LED driver's PWM registers, first enable software shutdown,
// then set up the mode and other settings, clear the PWM registers,
// then disable software shutdown.

// select "function register" bank
IS31_write_register( addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG );
IS31FL3731_write_register( addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG );

// enable software shutdown
IS31_write_register( addr, ISSI_REG_SHUTDOWN, 0x00 );
IS31FL3731_write_register( addr, ISSI_REG_SHUTDOWN, 0x00 );
// this delay was copied from other drivers, might not be needed
#ifdef __AVR__
_delay_ms( 10 );
Expand All @@ -155,47 +155,47 @@ void IS31_init( uint8_t addr )
#endif

// picture mode
IS31_write_register( addr, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE );
IS31FL3731_write_register( addr, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE );
// display frame 0
IS31_write_register( addr, ISSI_REG_PICTUREFRAME, 0x00 );
IS31FL3731_write_register( addr, ISSI_REG_PICTUREFRAME, 0x00 );
// audio sync off
IS31_write_register( addr, ISSI_REG_AUDIOSYNC, 0x00 );
IS31FL3731_write_register( addr, ISSI_REG_AUDIOSYNC, 0x00 );

// select bank 0
IS31_write_register( addr, ISSI_COMMANDREGISTER, 0 );
IS31FL3731_write_register( addr, ISSI_COMMANDREGISTER, 0 );

// turn off all LEDs in the LED control register
for ( int i = 0x00; i <= 0x11; i++ )
{
IS31_write_register( addr, i, 0x00 );
IS31FL3731_write_register( addr, i, 0x00 );
}

// turn off all LEDs in the blink control register (not really needed)
for ( int i = 0x12; i <= 0x23; i++ )
{
IS31_write_register( addr, i, 0x00 );
IS31FL3731_write_register( addr, i, 0x00 );
}

// set PWM on all LEDs to 0
for ( int i = 0x24; i <= 0xB3; i++ )
{
IS31_write_register( addr, i, 0x00 );
IS31FL3731_write_register( addr, i, 0x00 );
}

// select "function register" bank
IS31_write_register( addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG );
IS31FL3731_write_register( addr, ISSI_COMMANDREGISTER, ISSI_BANK_FUNCTIONREG );

// disable software shutdown
IS31_write_register( addr, ISSI_REG_SHUTDOWN, 0x01 );
IS31FL3731_write_register( addr, ISSI_REG_SHUTDOWN, 0x01 );

// select bank 0 and leave it selected.
// most usage after initialization is just writing PWM buffers in bank 0
// as there's not much point in double-buffering
IS31_write_register( addr, ISSI_COMMANDREGISTER, 0 );
IS31FL3731_write_register( addr, ISSI_COMMANDREGISTER, 0 );

}

void IS31_set_color( int index, uint8_t red, uint8_t green, uint8_t blue )
void IS31FL3731_set_color( int index, uint8_t red, uint8_t green, uint8_t blue )
{
if ( index >= 0 && index < DRIVER_LED_TOTAL ) {
is31_led led = g_is31_leds[index];
Expand All @@ -208,15 +208,15 @@ void IS31_set_color( int index, uint8_t red, uint8_t green, uint8_t blue )
}
}

void IS31_set_color_all( uint8_t red, uint8_t green, uint8_t blue )
void IS31FL3731_set_color_all( uint8_t red, uint8_t green, uint8_t blue )
{
for ( int i = 0; i < DRIVER_LED_TOTAL; i++ )
{
IS31_set_color( i, red, green, blue );
IS31FL3731_set_color( i, red, green, blue );
}
}

void IS31_set_led_control_register( uint8_t index, bool red, bool green, bool blue )
void IS31FL3731_set_led_control_register( uint8_t index, bool red, bool green, bool blue )
{
is31_led led = g_is31_leds[index];

Expand Down Expand Up @@ -247,24 +247,24 @@ void IS31_set_led_control_register( uint8_t index, bool red, bool green, bool bl

}

void IS31_update_pwm_buffers( uint8_t addr1, uint8_t addr2 )
void IS31FL3731_update_pwm_buffers( uint8_t addr1, uint8_t addr2 )
{
if ( g_pwm_buffer_update_required )
{
IS31_write_pwm_buffer( addr1, g_pwm_buffer[0] );
IS31_write_pwm_buffer( addr2, g_pwm_buffer[1] );
IS31FL3731_write_pwm_buffer( addr1, g_pwm_buffer[0] );
IS31FL3731_write_pwm_buffer( addr2, g_pwm_buffer[1] );
}
g_pwm_buffer_update_required = false;
}

void IS31_update_led_control_registers( uint8_t addr1, uint8_t addr2 )
void IS31FL3731_update_led_control_registers( uint8_t addr1, uint8_t addr2 )
{
if ( g_led_control_registers_update_required )
{
for ( int i=0; i<18; i++ )
{
IS31_write_register(addr1, i, g_led_control_registers[0][i] );
IS31_write_register(addr2, i, g_led_control_registers[1][i] );
IS31FL3731_write_register(addr1, i, g_led_control_registers[0][i] );
IS31FL3731_write_register(addr2, i, g_led_control_registers[1][i] );
}
}
}
Expand Down
Loading

0 comments on commit 33af5f8

Please sign in to comment.