From 60829a134a9b119b0fb6a672770c23ef6a4dfe65 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Fri, 10 Mar 2023 15:41:40 -0600 Subject: [PATCH] Make examples friendlier for non GCC compilers and fixed slave_mem_i2c.c to compile on boards without I2C pins (#336) --- CMakeLists.txt | 4 ++- adc/adc_console/adc_console.c | 3 ++- adc/microphone_adc/microphone_adc.c | 2 -- adc/onboard_temperature/onboard_temperature.c | 2 -- flash/cache_perfctr/flash_cache_perfctr.c | 4 ++- flash/nuke/nuke.c | 2 +- gpio/hello_7segment/hello_7segment.c | 2 -- gpio/hello_gpio_irq/hello_gpio_irq.c | 2 -- hello_world/serial/hello_serial.c | 1 - hello_world/usb/hello_usb.c | 1 - i2c/bmp280_i2c/bmp280_i2c.c | 3 +-- i2c/ht16k33_i2c/ht16k33_i2c.c | 2 -- i2c/lcd_1602_i2c/lcd_1602_i2c.c | 2 -- i2c/lis3dh_i2c/lis3dh_i2c.c | 3 +-- i2c/mma8451_i2c/mma8451_i2c.c | 2 +- i2c/mpl3115a2_i2c/mpl3115a2_i2c.c | 9 ++++--- i2c/mpu6050_i2c/mpu6050_i2c.c | 3 +-- i2c/pa1010d_i2c/pa1010d_i2c.c | 25 +++++++++---------- i2c/pcf8523_i2c/pcf8523_i2c.c | 3 +-- i2c/slave_mem_i2c/slave_mem_i2c.c | 8 ++++++ interp/hello_interp/hello_interp.c | 15 +++++++---- .../multicore_runner_queue.c | 9 +++---- pio/apa102/apa102.c | 6 ++++- pio/i2c/i2c.pio | 4 +-- pio/i2c/pio_i2c.c | 8 ++++++ pio/st7789_lcd/st7789_lcd.c | 8 ++++-- pio/ws2812/ws2812_parallel.c | 2 +- pwm/measure_duty_cycle/measure_duty_cycle.c | 2 +- rtc/hello_rtc/hello_rtc.c | 2 -- rtc/rtc_alarm_repeat/rtc_alarm_repeat.c | 2 -- spi/bme280_spi/bme280_spi.c | 2 -- spi/max7219_32x8_spi/max7219_32x8_spi.c | 2 -- spi/max7219_8x7seg_spi/max7219_8x7seg_spi.c | 2 -- spi/mpu9250_spi/mpu9250_spi.c | 2 -- system/narrow_io_write/narrow_io_write.c | 6 +++-- uart/lcd_uart/lcd_uart.c | 8 +++--- usb/CMakeLists.txt | 4 +-- usb/device/dev_hid_composite/main.c | 2 -- usb/device/dev_lowlevel/dev_lowlevel.c | 6 ++--- 39 files changed, 89 insertions(+), 86 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc91638..af5cca9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,8 +28,10 @@ add_subdirectory(hello_world) add_compile_options(-Wall -Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int -Wno-unused-function # we have some for the docs that aren't called - -Wno-maybe-uninitialized ) +if (CMAKE_C_COMPILER_ID STREQUAL "GNU") + add_compile_options(-Wno-maybe-uninitialized) +endif() # Hardware-specific examples in subdirectories: add_subdirectory(adc) diff --git a/adc/adc_console/adc_console.c b/adc/adc_console/adc_console.c index b212847..e076f15 100644 --- a/adc/adc_console/adc_console.c +++ b/adc/adc_console/adc_console.c @@ -72,7 +72,7 @@ int main(void) { printf("%03x\n", sample_buf[i]); break; } - case 'w': + case 'w': { printf("\nPress any key to stop wiggling\n"); int i = 1; gpio_set_dir_all_bits(-1); @@ -85,6 +85,7 @@ int main(void) { gpio_set_dir_all_bits(0); printf("Wiggling halted.\n"); break; + } case '\n': case '\r': break; diff --git a/adc/microphone_adc/microphone_adc.c b/adc/microphone_adc/microphone_adc.c index 2831e9b..6502a95 100644 --- a/adc/microphone_adc/microphone_adc.c +++ b/adc/microphone_adc/microphone_adc.c @@ -44,6 +44,4 @@ int main() { printf("%.2f\n", adc_raw * ADC_CONVERT); sleep_ms(10); } - - return 0; } diff --git a/adc/onboard_temperature/onboard_temperature.c b/adc/onboard_temperature/onboard_temperature.c index 1320895..d68a9c2 100644 --- a/adc/onboard_temperature/onboard_temperature.c +++ b/adc/onboard_temperature/onboard_temperature.c @@ -58,6 +58,4 @@ int main() { #endif sleep_ms(990); } - - return 0; } diff --git a/flash/cache_perfctr/flash_cache_perfctr.c b/flash/cache_perfctr/flash_cache_perfctr.c index 03b5d61..b894be6 100644 --- a/flash/cache_perfctr/flash_cache_perfctr.c +++ b/flash/cache_perfctr/flash_cache_perfctr.c @@ -79,7 +79,9 @@ int main() { printf("Hit rate so far: %.1f%%\n", hit * 100.f / access); printf("Calculate 25th fibonacci number: %d\n", recursive_fibonacci(25)); - printf("New hit rate after printf and fibonacci: %.1f%%\n", xip_ctrl_hw->ctr_hit * 100.f / xip_ctrl_hw->ctr_acc); + uint32_t ctr_hit = xip_ctrl_hw->ctr_hit; + uint32_t ctr_acc = xip_ctrl_hw->ctr_acc; + printf("New hit rate after printf and fibonacci: %.1f%%\n", ctr_hit * 100.f / ctr_acc); check_hit_miss_invalidate(); diff --git a/flash/nuke/nuke.c b/flash/nuke/nuke.c index 4666b9d..521f5d7 100644 --- a/flash/nuke/nuke.c +++ b/flash/nuke/nuke.c @@ -17,7 +17,7 @@ // // To the CMakeLists.txt app for this file. Just to be sure, we can check the // define: -#if !PICO_NO_FLASH +#if !PICO_NO_FLASH && !PICO_COPY_TO_RAM #error "This example must be built to run from SRAM!" #endif diff --git a/gpio/hello_7segment/hello_7segment.c b/gpio/hello_7segment/hello_7segment.c index 56162fd..8be257f 100644 --- a/gpio/hello_7segment/hello_7segment.c +++ b/gpio/hello_7segment/hello_7segment.c @@ -89,7 +89,5 @@ int main() { sleep_ms(250); gpio_clr_mask(mask); } - - return 0; } /// \end::hello_gpio[] diff --git a/gpio/hello_gpio_irq/hello_gpio_irq.c b/gpio/hello_gpio_irq/hello_gpio_irq.c index 8c63ba6..20d83b5 100644 --- a/gpio/hello_gpio_irq/hello_gpio_irq.c +++ b/gpio/hello_gpio_irq/hello_gpio_irq.c @@ -27,8 +27,6 @@ int main() { // Wait forever while (1); - - return 0; } diff --git a/hello_world/serial/hello_serial.c b/hello_world/serial/hello_serial.c index e9a011a..8c7b38f 100644 --- a/hello_world/serial/hello_serial.c +++ b/hello_world/serial/hello_serial.c @@ -13,5 +13,4 @@ int main() { printf("Hello, world!\n"); sleep_ms(1000); } - return 0; } diff --git a/hello_world/usb/hello_usb.c b/hello_world/usb/hello_usb.c index e9a011a..8c7b38f 100644 --- a/hello_world/usb/hello_usb.c +++ b/hello_world/usb/hello_usb.c @@ -13,5 +13,4 @@ int main() { printf("Hello, world!\n"); sleep_ms(1000); } - return 0; } diff --git a/i2c/bmp280_i2c/bmp280_i2c.c b/i2c/bmp280_i2c/bmp280_i2c.c index c056483..59fd2e7 100644 --- a/i2c/bmp280_i2c/bmp280_i2c.c +++ b/i2c/bmp280_i2c/bmp280_i2c.c @@ -214,6 +214,7 @@ int main() { #if !defined(i2c_default) || !defined(PICO_DEFAULT_I2C_SDA_PIN) || !defined(PICO_DEFAULT_I2C_SCL_PIN) #warning i2c / bmp280_i2c example requires a board with I2C pins puts("Default I2C pins were not defined"); + return 0; #else // useful information for picotool bi_decl(bi_2pins_with_func(PICO_DEFAULT_I2C_SDA_PIN, PICO_DEFAULT_I2C_SCL_PIN, GPIO_FUNC_I2C)); @@ -248,7 +249,5 @@ int main() { // poll every 500ms sleep_ms(500); } - #endif - return 0; } diff --git a/i2c/ht16k33_i2c/ht16k33_i2c.c b/i2c/ht16k33_i2c/ht16k33_i2c.c index 15657b0..2ef8a3c 100644 --- a/i2c/ht16k33_i2c/ht16k33_i2c.c +++ b/i2c/ht16k33_i2c/ht16k33_i2c.c @@ -224,7 +224,5 @@ again: ht16k33_set_blink(0); goto again; - - return 0; #endif } diff --git a/i2c/lcd_1602_i2c/lcd_1602_i2c.c b/i2c/lcd_1602_i2c/lcd_1602_i2c.c index 7ab27fe..28ce208 100644 --- a/i2c/lcd_1602_i2c/lcd_1602_i2c.c +++ b/i2c/lcd_1602_i2c/lcd_1602_i2c.c @@ -163,7 +163,5 @@ int main() { lcd_clear(); } } - - return 0; #endif } diff --git a/i2c/lis3dh_i2c/lis3dh_i2c.c b/i2c/lis3dh_i2c/lis3dh_i2c.c index 0de5094..f3d9169 100644 --- a/i2c/lis3dh_i2c/lis3dh_i2c.c +++ b/i2c/lis3dh_i2c/lis3dh_i2c.c @@ -122,8 +122,7 @@ int main() { sleep_ms(500); // Clear terminal - printf("\e[1;1H\e[2J"); + printf("\033[1;1H\033[2J"); } #endif - return 0; } diff --git a/i2c/mma8451_i2c/mma8451_i2c.c b/i2c/mma8451_i2c/mma8451_i2c.c index 453f5f3..27a9a56 100644 --- a/i2c/mma8451_i2c/mma8451_i2c.c +++ b/i2c/mma8451_i2c/mma8451_i2c.c @@ -121,7 +121,7 @@ int main() { sleep_ms(500); // Clear terminal - printf("\e[1;1H\e[2J"); + printf("\033[1;1H\033[2J"); } #endif diff --git a/i2c/mpl3115a2_i2c/mpl3115a2_i2c.c b/i2c/mpl3115a2_i2c/mpl3115a2_i2c.c index b98a1b4..ad9c0c9 100644 --- a/i2c/mpl3115a2_i2c/mpl3115a2_i2c.c +++ b/i2c/mpl3115a2_i2c/mpl3115a2_i2c.c @@ -148,12 +148,15 @@ void mpl3115a2_convert_fifo_batch(uint8_t start, volatile uint8_t buf[], struct // 3 altitude registers: MSB (8 bits), CSB (8 bits) and LSB (4 bits, starting from MSB) // first two are integer bits (2's complement) and LSB is fractional bits -> makes 20 bit signed integer - int32_t h = (int32_t) ((uint32_t) buf[start] << 24 | buf[start + 1] << 16 | buf[start + 2] << 8); + int32_t h = (int32_t) buf[start] << 24; + h |= (int32_t) buf[start + 1] << 16; + h |= (int32_t) buf[start + 2] << 8; data->altitude = ((float)h) / 65536.f; // 2 temperature registers: MSB (8 bits) and LSB (4 bits, starting from MSB) // first 8 are integer bits with sign and LSB is fractional bits -> 12 bit signed integer - int16_t t = (int16_t) (((uint16_t) buf[start + 3]) << 8 | buf[start + 4]); + int16_t t = (int16_t) buf[start + 3] << 8; + t |= (int16_t) buf[start + 4]; data->temperature = ((float)t) / 256.f; } @@ -162,6 +165,7 @@ int main() { #if !defined(i2c_default) || !defined(PICO_DEFAULT_I2C_SDA_PIN) || !defined(PICO_DEFAULT_I2C_SCL_PIN) #warning i2c / mpl3115a2_i2c example requires a board with I2C pins puts("Default I2C pins were not defined"); + return 0; #else printf("Hello, MPL3115A2. Waiting for something to interrupt me!...\n"); @@ -202,5 +206,4 @@ int main() { }; #endif - return 0; } diff --git a/i2c/mpu6050_i2c/mpu6050_i2c.c b/i2c/mpu6050_i2c/mpu6050_i2c.c index d0bc532..9f14e8c 100644 --- a/i2c/mpu6050_i2c/mpu6050_i2c.c +++ b/i2c/mpu6050_i2c/mpu6050_i2c.c @@ -82,6 +82,7 @@ int main() { #if !defined(i2c_default) || !defined(PICO_DEFAULT_I2C_SDA_PIN) || !defined(PICO_DEFAULT_I2C_SCL_PIN) #warning i2c/mpu6050_i2c example requires a board with I2C pins puts("Default I2C pins were not defined"); + return 0; #else printf("Hello, MPU6050! Reading raw data from registers...\n"); @@ -111,7 +112,5 @@ int main() { sleep_ms(100); } - #endif - return 0; } diff --git a/i2c/pa1010d_i2c/pa1010d_i2c.c b/i2c/pa1010d_i2c/pa1010d_i2c.c index 4de0651..0a8f1b6 100644 --- a/i2c/pa1010d_i2c/pa1010d_i2c.c +++ b/i2c/pa1010d_i2c/pa1010d_i2c.c @@ -24,7 +24,7 @@ */ const int addr = 0x10; -const int max_read = 250; +#define MAX_READ 250 #ifdef i2c_default @@ -44,24 +44,24 @@ void pa1010d_parse_string(char output[], char protocol[]) { int p = com_index - output; // Splits components of output sentence into array - int no_of_fields = 14; - int max_len = 15; +#define NO_OF_FIELDS 14 +#define MAX_LEN 15 int n = 0; int m = 0; - char gps_data[no_of_fields][max_len]; + char gps_data[NO_OF_FIELDS][MAX_LEN]; memset(gps_data, 0, sizeof(gps_data)); bool complete = false; - while (output[p] != '$' && n < max_len && complete == false) { + while (output[p] != '$' && n < MAX_LEN && complete == false) { if (output[p] == ',' || output[p] == '*') { n += 1; m = 0; } else { gps_data[n][m] = output[p]; // Checks if sentence is complete - if (m < no_of_fields) { + if (m < NO_OF_FIELDS) { m++; } else { complete = true; @@ -92,15 +92,15 @@ void pa1010d_parse_string(char output[], char protocol[]) { } void pa1010d_read_raw(char numcommand[]) { - uint8_t buffer[max_read]; + uint8_t buffer[MAX_READ]; int i = 0; bool complete = false; - i2c_read_blocking(i2c_default, addr, buffer, max_read, false); + i2c_read_blocking(i2c_default, addr, buffer, MAX_READ, false); // Convert bytes to characters - while (i < max_read && complete == false) { + while (i < MAX_READ && complete == false) { numcommand[i] = buffer[i]; // Stop converting at end of message if (buffer[i] == 10 && buffer[i + 1] == 10) { @@ -119,7 +119,7 @@ int main() { puts("Default I2C pins were not defined"); #else - char numcommand[max_read]; + char numcommand[MAX_READ]; // Decide which protocols you would like to retrieve data from char init_command[] = "$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29\r\n"; @@ -140,7 +140,7 @@ int main() { while (1) { // Clear array - memset(numcommand, 0, max_read); + memset(numcommand, 0, MAX_READ); // Read and re-format pa1010d_read_raw(numcommand); pa1010d_parse_string(numcommand, "GNRMC"); @@ -149,8 +149,7 @@ int main() { sleep_ms(1000); // Clear terminal - printf("\e[1;1H\e[2J"); + printf("\033[1;1H\033[2J"); } #endif - return 0; } diff --git a/i2c/pcf8523_i2c/pcf8523_i2c.c b/i2c/pcf8523_i2c/pcf8523_i2c.c index 31046a3..232e0f1 100644 --- a/i2c/pcf8523_i2c/pcf8523_i2c.c +++ b/i2c/pcf8523_i2c/pcf8523_i2c.c @@ -156,9 +156,8 @@ int main() { sleep_ms(500); // Clear terminal - printf("\e[1;1H\e[2J"); + printf("\033[1;1H\033[2J"); } #endif - return 0; } diff --git a/i2c/slave_mem_i2c/slave_mem_i2c.c b/i2c/slave_mem_i2c/slave_mem_i2c.c index 776e459..64a9eec 100644 --- a/i2c/slave_mem_i2c/slave_mem_i2c.c +++ b/i2c/slave_mem_i2c/slave_mem_i2c.c @@ -14,6 +14,7 @@ static const uint I2C_SLAVE_ADDRESS = 0x17; static const uint I2C_BAUDRATE = 100000; // 100 kHz +#ifdef i2c_default // For this example, we run both the master and slave from the same board. // You'll need to wire pin GP4 to GP6 (SDA), and pin GP5 to GP7 (SCL). static const uint I2C_SLAVE_SDA_PIN = PICO_DEFAULT_I2C_SDA_PIN; // 4 @@ -124,11 +125,18 @@ static void run_master() { sleep_ms(2000); } } +#endif int main() { stdio_init_all(); +#if !defined(i2c_default) || !defined(PICO_DEFAULT_I2C_SDA_PIN) || !defined(PICO_DEFAULT_I2C_SCL_PIN) +#warning i2c / slave_mem_i2c example requires a board with I2C pins + puts("Default I2C pins were not defined"); + return 0; +#else puts("\nI2C slave example"); setup_slave(); run_master(); +#endif } diff --git a/interp/hello_interp/hello_interp.c b/interp/hello_interp/hello_interp.c index 3c3bf6e..75e855a 100644 --- a/interp/hello_interp/hello_interp.c +++ b/interp/hello_interp/hello_interp.c @@ -58,8 +58,11 @@ void cross_lanes() { interp0->base[0] = 1; interp0->base[1] = 0; puts("Lane result crossover:"); - for (int i = 0; i < 10; ++i) - printf("PEEK0, POP1: %d, %d\n", interp0->peek[0], interp0->pop[1]); + for (int i = 0; i < 10; ++i) { + uint32_t peek0 = interp0->peek[0]; + uint32_t pop1 = interp0->pop[1]; + printf("PEEK0, POP1: %d, %d\n", peek0, pop1); + } } void simple_blend1() { @@ -107,7 +110,7 @@ void simple_blend2() { interp_config_set_blend(&cfg, true); interp_set_config(interp0, 0, &cfg); - interp0->base[0] = -1000; + interp0->base[0] = (uint32_t) -1000; interp0->base[1] = 1000; puts("signed:"); @@ -178,8 +181,10 @@ void linear_interpolation() { int16_t *sample_pair = (int16_t *) interp0->peek[2]; interp0->base[0] = sample_pair[0]; interp0->base[1] = sample_pair[1]; - printf("%d\t(%d%% between %d and %d)\n", (int) interp0->peek[1], - 100 * (interp0->add_raw[1] & 0xff) / 0xff, + uint32_t peek1 = interp0->peek[1]; + uint32_t add_raw1 = interp0->add_raw[1]; + printf("%d\t(%d%% between %d and %d)\n", (int) peek1, + 100 * (add_raw1 & 0xff) / 0xff, sample_pair[0], sample_pair[1]); interp0->add_raw[0] = step; } diff --git a/multicore/multicore_runner_queue/multicore_runner_queue.c b/multicore/multicore_runner_queue/multicore_runner_queue.c index 937adf3..046cda4 100644 --- a/multicore/multicore_runner_queue/multicore_runner_queue.c +++ b/multicore/multicore_runner_queue/multicore_runner_queue.c @@ -13,7 +13,7 @@ typedef struct { - void *func; + int32_t (*func)(int32_t); int32_t data; } queue_entry_t; @@ -31,8 +31,7 @@ void core1_entry() { queue_remove_blocking(&call_queue, &entry); - int32_t (*func)() = (int32_t(*)())(entry.func); - int32_t result = (*func)(entry.data); + int32_t result = entry.func(entry.data); queue_add_blocking(&results_queue, &result); } @@ -78,7 +77,7 @@ int main() { multicore_launch_core1(core1_entry); - queue_entry_t entry = {&factorial, TEST_NUM}; + queue_entry_t entry = {factorial, TEST_NUM}; queue_add_blocking(&call_queue, &entry); // We could now do a load of stuff on core 0 and get our result later @@ -88,7 +87,7 @@ int main() { printf("Factorial %d is %d\n", TEST_NUM, res); // Now try a different function - entry.func = &fibonacci; + entry.func = fibonacci; queue_add_blocking(&call_queue, &entry); queue_remove_blocking(&results_queue, &res); diff --git a/pio/apa102/apa102.c b/pio/apa102/apa102.c index 152945a..e85abe1 100644 --- a/pio/apa102/apa102.c +++ b/pio/apa102/apa102.c @@ -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) { diff --git a/pio/i2c/i2c.pio b/pio/i2c/i2c.pio index 65f3e78..675261c 100644 --- a/pio/i2c/i2c.pio +++ b/pio/i2c/i2c.pio @@ -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 diff --git a/pio/i2c/pio_i2c.c b/pio/i2c/pio_i2c.c index ef47e4b..a3a19f5 100644 --- a/pio/i2c/pio_i2c.c +++ b/pio/i2c/pio_i2c.c @@ -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) { diff --git a/pio/st7789_lcd/st7789_lcd.c b/pio/st7789_lcd/st7789_lcd.c index 29a645a..26862c5 100644 --- a/pio/st7789_lcd/st7789_lcd.c +++ b/pio/st7789_lcd/st7789_lcd.c @@ -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]; diff --git a/pio/ws2812/ws2812_parallel.c b/pio/ws2812/ws2812_parallel.c index 4b5ae9e..8d3e85e 100644 --- a/pio/ws2812/ws2812_parallel.c +++ b/pio/ws2812/ws2812_parallel.c @@ -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! diff --git a/pwm/measure_duty_cycle/measure_duty_cycle.c b/pwm/measure_duty_cycle/measure_duty_cycle.c index 9cd1137..cffe405 100644 --- a/pwm/measure_duty_cycle/measure_duty_cycle.c +++ b/pwm/measure_duty_cycle/measure_duty_cycle.c @@ -64,7 +64,7 @@ int main() { // values should be very close! for (int i = 0; i < count_of(test_duty_cycles); ++i) { float output_duty_cycle = test_duty_cycles[i]; - pwm_set_gpio_level(OUTPUT_PIN, output_duty_cycle * (count_top + 1)); + pwm_set_gpio_level(OUTPUT_PIN, (uint16_t) (output_duty_cycle * (count_top + 1))); float measured_duty_cycle = measure_duty_cycle(MEASURE_PIN); printf("Output duty cycle = %.1f%%, measured input duty cycle = %.1f%%\n", output_duty_cycle * 100.f, measured_duty_cycle * 100.f); diff --git a/rtc/hello_rtc/hello_rtc.c b/rtc/hello_rtc/hello_rtc.c index b59cea0..69472b5 100644 --- a/rtc/hello_rtc/hello_rtc.c +++ b/rtc/hello_rtc/hello_rtc.c @@ -43,7 +43,5 @@ int main() { printf("\r%s ", datetime_str); sleep_ms(100); } - - return 0; } /// \end::hello_rtc_main[] diff --git a/rtc/rtc_alarm_repeat/rtc_alarm_repeat.c b/rtc/rtc_alarm_repeat/rtc_alarm_repeat.c index fbb9592..414d23d 100644 --- a/rtc/rtc_alarm_repeat/rtc_alarm_repeat.c +++ b/rtc/rtc_alarm_repeat/rtc_alarm_repeat.c @@ -56,6 +56,4 @@ int main() { // Alarm will keep firing forever while(1); - - return 0; } \ No newline at end of file diff --git a/spi/bme280_spi/bme280_spi.c b/spi/bme280_spi/bme280_spi.c index 2beea28..c6c50b1 100644 --- a/spi/bme280_spi/bme280_spi.c +++ b/spi/bme280_spi/bme280_spi.c @@ -235,7 +235,5 @@ int main() { sleep_ms(1000); } - - return 0; #endif } diff --git a/spi/max7219_32x8_spi/max7219_32x8_spi.c b/spi/max7219_32x8_spi/max7219_32x8_spi.c index d00e683..0f2926d 100644 --- a/spi/max7219_32x8_spi/max7219_32x8_spi.c +++ b/spi/max7219_32x8_spi/max7219_32x8_spi.c @@ -135,7 +135,5 @@ int main() { bright++; } - - return 0; #endif } diff --git a/spi/max7219_8x7seg_spi/max7219_8x7seg_spi.c b/spi/max7219_8x7seg_spi/max7219_8x7seg_spi.c index 2268a5b..156f771 100644 --- a/spi/max7219_8x7seg_spi/max7219_8x7seg_spi.c +++ b/spi/max7219_8x7seg_spi/max7219_8x7seg_spi.c @@ -142,7 +142,5 @@ int main() { j = 0; } } - - return 0; #endif } diff --git a/spi/mpu9250_spi/mpu9250_spi.c b/spi/mpu9250_spi/mpu9250_spi.c index aab48ca..52bb6b8 100644 --- a/spi/mpu9250_spi/mpu9250_spi.c +++ b/spi/mpu9250_spi/mpu9250_spi.c @@ -150,6 +150,4 @@ int main() { sleep_ms(100); } - - return 0; } diff --git a/system/narrow_io_write/narrow_io_write.c b/system/narrow_io_write/narrow_io_write.c index e4aa2f4..cf30f36 100644 --- a/system/narrow_io_write/narrow_io_write.c +++ b/system/narrow_io_write/narrow_io_write.c @@ -37,8 +37,10 @@ int main() { // on transfer size and address LSBs printf("\nReading back 1 byte at a time\n"); // Little-endian! - printf("Should be ef be ad de: %02x %02x %02x %02x\n", - scratch8[0], scratch8[1], scratch8[2], scratch8[3]); + printf("Should be ef be ad de: %02x ", scratch8[0]); + printf("%02x ", scratch8[1]); + printf("%02x ", scratch8[2]); + printf("%02x\n", scratch8[3]); // The Cortex-M0+ and the RP2040 DMA replicate byte writes across the bus, // and IO registers will sample the entire write bus always. diff --git a/uart/lcd_uart/lcd_uart.c b/uart/lcd_uart/lcd_uart.c index e68b9e0..79456f3 100644 --- a/uart/lcd_uart/lcd_uart.c +++ b/uart/lcd_uart/lcd_uart.c @@ -151,7 +151,7 @@ int main() { #if LCD_IS_RGB uint8_t i = 0; // it's ok if this overflows and wraps, we're using sin const float frequency = 0.1f; - float red, green, blue; + uint8_t red, green, blue; #endif while (1) { @@ -163,9 +163,9 @@ int main() { if (c < 128) uart_putc_raw(UART_ID, c); // skip extra non-ASCII chars #if LCD_IS_RGB // change the display color on keypress, rainbow style! - red = sin(frequency * i + 0) * 127 + 128; - green = sin(frequency * i + 2) * 127 + 128; - blue = sin(frequency * i + 4) * 127 + 128; + red = (uint8_t)(sin(frequency * i + 0) * 127 + 128); + green = (uint8_t)(sin(frequency * i + 2) * 127 + 128); + blue = (uint8_t)(sin(frequency * i + 4) * 127 + 128); lcd_set_backlight_color(red, green, blue); i++; #endif diff --git a/usb/CMakeLists.txt b/usb/CMakeLists.txt index 7a511c7..2e75b2f 100644 --- a/usb/CMakeLists.txt +++ b/usb/CMakeLists.txt @@ -9,8 +9,8 @@ else () message("Skipping TinyUSB host examples as TinyUSB is unavailable") endif () if (TARGET tinyusb_pico_pio_usb) - if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 11.3) - message("Skipping TinyUSB dual examples, as TinyUSB hw/mcu/raspberry_pi/Pico-PIO-USB does not currently compile on GCC 11.3 or greater") + if ((NOT CMAKE_C_COMPILER_ID STREQUAL "GNU") OR CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 11.3) + message("Skipping TinyUSB dual examples, as TinyUSB hw/mcu/raspberry_pi/Pico-PIO-USB does not currently compile on non GCC or GCC 11.3 or greater") else() add_subdirectory(dual) endif() diff --git a/usb/device/dev_hid_composite/main.c b/usb/device/dev_hid_composite/main.c index 1158cf1..0b53762 100644 --- a/usb/device/dev_hid_composite/main.c +++ b/usb/device/dev_hid_composite/main.c @@ -65,8 +65,6 @@ int main(void) hid_task(); } - - return 0; } //--------------------------------------------------------------------+ diff --git a/usb/device/dev_lowlevel/dev_lowlevel.c b/usb/device/dev_lowlevel/dev_lowlevel.c index 2191c4f..31c3f63 100644 --- a/usb/device/dev_lowlevel/dev_lowlevel.c +++ b/usb/device/dev_lowlevel/dev_lowlevel.c @@ -26,8 +26,8 @@ // Device descriptors #include "dev_lowlevel.h" -#define usb_hw_set hw_set_alias(usb_hw) -#define usb_hw_clear hw_clear_alias(usb_hw) +#define usb_hw_set ((usb_hw_t *)hw_set_alias_untyped(usb_hw)) +#define usb_hw_clear ((usb_hw_t *)hw_clear_alias_untyped(usb_hw)) // Function prototypes for our device specific endpoint handlers defined // later on @@ -575,6 +575,4 @@ int main(void) { while (1) { tight_loop_contents(); } - - return 0; }