Skip to content

Commit

Permalink
__flash? (qmk#13799)
Browse files Browse the repository at this point in the history
  • Loading branch information
zvecr authored Jul 31, 2021
1 parent 377b991 commit c8d6524
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/feature_led_matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Here is an example using 2 drivers.
Define these arrays listing all the LEDs in your `<keyboard>.c`:
```c
const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | LED address
Expand Down
8 changes: 4 additions & 4 deletions docs/feature_rgb_matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Here is an example using 2 drivers.
Define these arrays listing all the LEDs in your `<keyboard>.c`:
```c
const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
Expand Down Expand Up @@ -122,7 +122,7 @@ Currently only 4 drivers are supported, but it would be trivial to support all 8
Define these arrays listing all the LEDs in your `<keyboard>.c`:
```c
const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
Expand Down Expand Up @@ -186,7 +186,7 @@ Currently only 2 drivers are supported, but it would be trivial to support all 4
Define these arrays listing all the LEDs in your `<keyboard>.c`:
```c
const is31_led PROGMEM g_is31_leds[DRIVER_LED_TOTAL] = {
const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* Refer to IS31 manual for these locations
* driver
* | R location
Expand Down Expand Up @@ -287,7 +287,7 @@ Here is an example using 2 drivers.
Define these arrays listing all the LEDs in your `<keyboard>.c`:
```c
const aw_led g_aw_leds[DRIVER_LED_TOTAL] = {
const aw_led __flash g_aw_leds[DRIVER_LED_TOTAL] = {
/* Each AW20216 channel is controlled by a register at some offset between 0x00
* and 0xD7 inclusive.
* See drivers/awinic/aw20216.h for the mapping between register offsets and
Expand Down
2 changes: 1 addition & 1 deletion docs/ja/feature_led_matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ I2C IS31FL3731 RGB コントローラを使ったアドレス指定可能な LED

`<keyboard>.c` に全ての LED を列挙する配列を定義します:

const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
/* これらの位置については IS31 マニュアルを参照してください
* driver
* | LED address
Expand Down
3 changes: 2 additions & 1 deletion drivers/led/aw20216.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <stdint.h>
#include <stdbool.h>
#include "progmem.h"
#include "gpio.h"

typedef struct aw_led {
Expand All @@ -27,7 +28,7 @@ typedef struct aw_led {
uint8_t b;
} aw_led;

extern const aw_led g_aw_leds[DRIVER_LED_TOTAL];
extern const aw_led __flash g_aw_leds[DRIVER_LED_TOTAL];

void AW20216_init(pin_t cs_pin, pin_t en_pin);
void AW20216_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
Expand Down
3 changes: 2 additions & 1 deletion drivers/led/issi/is31fl3731-simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@

#include <stdint.h>
#include <stdbool.h>
#include "progmem.h"

typedef struct is31_led {
uint8_t driver : 2;
uint8_t v;
} __attribute__((packed)) is31_led;

extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
extern const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL];

void IS31FL3731_init(uint8_t addr);
void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data);
Expand Down
3 changes: 2 additions & 1 deletion drivers/led/issi/is31fl3731.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <stdint.h>
#include <stdbool.h>
#include "progmem.h"

typedef struct is31_led {
uint8_t driver : 2;
Expand All @@ -27,7 +28,7 @@ typedef struct is31_led {
uint8_t b;
} __attribute__((packed)) is31_led;

extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
extern const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL];

void IS31FL3731_init(uint8_t addr);
void IS31FL3731_write_register(uint8_t addr, uint8_t reg, uint8_t data);
Expand Down
3 changes: 2 additions & 1 deletion drivers/led/issi/is31fl3733.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <stdint.h>
#include <stdbool.h>
#include "progmem.h"

typedef struct is31_led {
uint8_t driver : 2;
Expand All @@ -28,7 +29,7 @@ typedef struct is31_led {
uint8_t b;
} __attribute__((packed)) is31_led;

extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
extern const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL];

void IS31FL3733_init(uint8_t addr, uint8_t sync);
bool IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data);
Expand Down
3 changes: 2 additions & 1 deletion drivers/led/issi/is31fl3736.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <stdint.h>
#include <stdbool.h>
#include "progmem.h"

// Simple interface option.
// If these aren't defined, just define them to make it compile
Expand All @@ -37,7 +38,7 @@ typedef struct is31_led {
uint8_t b;
} __attribute__((packed)) is31_led;

extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
extern const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL];

void IS31FL3736_init(uint8_t addr);
void IS31FL3736_write_register(uint8_t addr, uint8_t reg, uint8_t data);
Expand Down
9 changes: 2 additions & 7 deletions drivers/led/issi/is31fl3737.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "is31fl3737.h"
#include "i2c_master.h"
#include "wait.h"
#include "progmem.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)
Expand Down Expand Up @@ -155,9 +154,7 @@ void IS31FL3737_init(uint8_t addr) {

void IS31FL3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
if (index >= 0 && index < DRIVER_LED_TOTAL) {
// copy the led config from progmem to SRAM
is31_led led;
memcpy_P(&led, (&g_is31_leds[index]), sizeof(led));
is31_led led = g_is31_leds[index];

g_pwm_buffer[led.driver][led.r] = red;
g_pwm_buffer[led.driver][led.g] = green;
Expand All @@ -173,9 +170,7 @@ void IS31FL3737_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
}

void IS31FL3737_set_led_control_register(uint8_t index, bool red, bool green, bool blue) {
// copy the led config from progmem to SRAM
is31_led led;
memcpy_P(&led, (&g_is31_leds[index]), sizeof(led));
is31_led led = g_is31_leds[index];

uint8_t control_register_r = led.r / 8;
uint8_t control_register_g = led.g / 8;
Expand Down
3 changes: 2 additions & 1 deletion drivers/led/issi/is31fl3737.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <stdint.h>
#include <stdbool.h>
#include "progmem.h"

typedef struct is31_led {
uint8_t driver : 2;
Expand All @@ -28,7 +29,7 @@ typedef struct is31_led {
uint8_t b;
} __attribute__((packed)) is31_led;

extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
extern const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL];

void IS31FL3737_init(uint8_t addr);
void IS31FL3737_write_register(uint8_t addr, uint8_t reg, uint8_t data);
Expand Down
3 changes: 2 additions & 1 deletion drivers/led/issi/is31fl3741.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <stdint.h>
#include <stdbool.h>
#include "progmem.h"

typedef struct is31_led {
uint32_t driver : 2;
Expand All @@ -29,7 +30,7 @@ typedef struct is31_led {
uint32_t b : 10;
} __attribute__((packed)) is31_led;

extern const is31_led g_is31_leds[DRIVER_LED_TOTAL];
extern const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL];

void IS31FL3741_init(uint8_t addr);
void IS31FL3741_write_register(uint8_t addr, uint8_t reg, uint8_t data);
Expand Down
1 change: 1 addition & 0 deletions tmk_core/common/progmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#else
# include <string.h>
# define PROGMEM
# define __flash
# define PSTR(x) x
# define PGM_P const char*
# define memcpy_P(dest, src, n) memcpy(dest, src, n)
Expand Down

0 comments on commit c8d6524

Please sign in to comment.