Make examples friendlier for non GCC compilers and fixed slave_mem_i2c.c to compile on boards without I2C pins (#336)

This commit is contained in:
Graham Sanderson
2023-03-10 15:41:40 -06:00
committed by GitHub
parent 9d3fea1419
commit 60829a134a
39 changed files with 89 additions and 86 deletions

View File

@@ -20,6 +20,10 @@
// Global brightness value 0->31
#define BRIGHTNESS 16
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
void put_start_frame(PIO pio, uint sm) {
pio_sm_put_blocking(pio, sm, 0u);
}
@@ -50,7 +54,7 @@ int main() {
apa102_mini_program_init(pio, sm, offset, SERIAL_FREQ, PIN_CLK, PIN_DIN);
for (int i = 0; i < TABLE_SIZE; ++i)
wave_table[i] = powf(sinf(i * M_PI / TABLE_SIZE), 5.f) * 255;
wave_table[i] = (uint8_t) (powf(sinf(i * M_PI / TABLE_SIZE), 5.f) * 255);
uint t = 0;
while (true) {

View File

@@ -110,8 +110,8 @@ static inline void i2c_program_init(PIO pio, uint sm, uint offset, uint pin_sda,
// Clear IRQ flag before starting, and make sure flag doesn't actually
// assert a system-level interrupt (we're using it as a status flag)
pio_set_irq0_source_enabled(pio, pis_interrupt0 + sm, false);
pio_set_irq1_source_enabled(pio, pis_interrupt0 + sm, false);
pio_set_irq0_source_enabled(pio, (enum pio_interrupt_source) ((uint) pis_interrupt0 + sm), false);
pio_set_irq1_source_enabled(pio, (enum pio_interrupt_source) ((uint) pis_interrupt0 + sm), false);
pio_interrupt_clear(pio, sm);
// Configure and start SM

View File

@@ -33,10 +33,14 @@ static inline void pio_i2c_put16(PIO pio, uint sm, uint16_t data) {
while (pio_sm_is_tx_fifo_full(pio, sm))
;
// some versions of GCC dislike this
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif
*(io_rw_16 *)&pio->txf[sm] = data;
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
}
@@ -48,10 +52,14 @@ void pio_i2c_put_or_err(PIO pio, uint sm, uint16_t data) {
if (pio_i2c_check_error(pio, sm))
return;
// some versions of GCC dislike this
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif
*(io_rw_16 *)&pio->txf[sm] = data;
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
}
uint8_t pio_i2c_get(PIO pio, uint sm) {

View File

@@ -30,6 +30,10 @@
#define SERIAL_CLK_DIV 1.f
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
// Format: cmd length (including cmd byte), post delay in units of 5 ms, then cmd payload
// Note the delays have been shortened a little
static const uint8_t st7789_init_seq[] = {
@@ -130,8 +134,8 @@ int main() {
if (theta > theta_max)
theta -= theta_max;
int32_t rotate[4] = {
cosf(theta) * (1 << UNIT_LSB), -sinf(theta) * (1 << UNIT_LSB),
sinf(theta) * (1 << UNIT_LSB), cosf(theta) * (1 << UNIT_LSB)
(int32_t) (cosf(theta) * (1 << UNIT_LSB)), (int32_t) (-sinf(theta) * (1 << UNIT_LSB)),
(int32_t) (sinf(theta) * (1 << UNIT_LSB)), (int32_t) (cosf(theta) * (1 << UNIT_LSB))
};
interp0->base[0] = rotate[0];
interp0->base[1] = rotate[2];

View File

@@ -83,9 +83,9 @@ void pattern_solid(uint len, uint t) {
}
}
int level = 8;
void pattern_fade(uint len, uint t) {
const int level = 8;
uint shift = 4;
uint max = 16; // let's not draw too much current!