Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for building with IAR #276

Draft
wants to merge 12 commits into
base: develop
Choose a base branch
from
3 changes: 2 additions & 1 deletion adc/adc_console/adc_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -85,6 +85,7 @@ int main(void) {
gpio_set_dir_all_bits(0);
printf("Wiggling halted.\n");
break;
}
case '\n':
case '\r':
break;
Expand Down
2 changes: 0 additions & 2 deletions adc/microphone_adc/microphone_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,4 @@ int main() {
printf("%.2f\n", adc_raw * ADC_CONVERT);
sleep_ms(10);
}

return 0;
}
2 changes: 0 additions & 2 deletions adc/onboard_temperature/onboard_temperature.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,4 @@ int main() {
#endif
sleep_ms(990);
}

return 0;
}
4 changes: 3 additions & 1 deletion flash/cache_perfctr/flash_cache_perfctr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 0 additions & 2 deletions gpio/hello_7segment/hello_7segment.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,5 @@ int main() {
sleep_ms(250);
gpio_clr_mask(mask);
}

return 0;
}
/// \end::hello_gpio[]
2 changes: 0 additions & 2 deletions gpio/hello_gpio_irq/hello_gpio_irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ int main() {

// Wait forever
while (1);

return 0;
}


Expand Down
1 change: 0 additions & 1 deletion hello_world/serial/hello_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ int main() {
printf("Hello, world!\n");
sleep_ms(1000);
}
return 0;
}
1 change: 0 additions & 1 deletion hello_world/usb/hello_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ int main() {
printf("Hello, world!\n");
sleep_ms(1000);
}
return 0;
}
3 changes: 1 addition & 2 deletions i2c/bmp280_i2c/bmp280_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -248,7 +249,5 @@ int main() {
// poll every 500ms
sleep_ms(500);
}

#endif
return 0;
}
2 changes: 0 additions & 2 deletions i2c/lcd_1602_i2c/lcd_1602_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,5 @@ int main() {
lcd_clear();
}
}

return 0;
#endif
}
3 changes: 1 addition & 2 deletions i2c/lis3dh_i2c/lis3dh_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ int main() {
sleep_ms(500);

// Clear terminal
printf("\e[1;1H\e[2J");
printf("%c[1;1H%c[2J", 27, 27);
}
#endif
return 0;
}
2 changes: 1 addition & 1 deletion i2c/mma8451_i2c/mma8451_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int main() {
sleep_ms(500);

// Clear terminal
printf("\e[1;1H\e[2J");
printf("%c[1;1H%c[2J", 27, 27);
}

#endif
Expand Down
9 changes: 6 additions & 3 deletions i2c/mpl3115a2_i2c/mpl3115a2_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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");

Expand Down Expand Up @@ -202,5 +206,4 @@ int main() {
};

#endif
return 0;
}
3 changes: 1 addition & 2 deletions i2c/mpu6050_i2c/mpu6050_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -111,7 +112,5 @@ int main() {

sleep_ms(100);
}

#endif
return 0;
}
3 changes: 1 addition & 2 deletions i2c/pa1010d_i2c/pa1010d_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ int main() {
sleep_ms(1000);

// Clear terminal
printf("\e[1;1H\e[2J");
printf("%c[1;1H%c[2J", 27, 27);
}
#endif
return 0;
}
3 changes: 1 addition & 2 deletions i2c/pcf8523_i2c/pcf8523_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,8 @@ int main() {
sleep_ms(500);

// Clear terminal
printf("\e[1;1H\e[2J");
printf("%c[1;1H%c[2J", 27, 27);
}
#endif
return 0;
}

15 changes: 10 additions & 5 deletions interp/hello_interp/hello_interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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:");
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 4 additions & 5 deletions multicore/multicore_runner_queue/multicore_runner_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

typedef struct
{
void *func;
int32_t (*func)(int32_t);
int32_t data;
} queue_entry_t;

Expand All @@ -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);
}
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion pio/apa102/apa102.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions pio/i2c/i2c.pio
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions pio/i2c/pio_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


Expand All @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions pio/st7789_lcd/st7789_lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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[] = {
Expand Down Expand Up @@ -129,8 +133,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];
Expand Down
2 changes: 1 addition & 1 deletion pwm/measure_duty_cycle/measure_duty_cycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions rtc/hello_rtc/hello_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,5 @@ int main() {
printf("\r%s ", datetime_str);
sleep_ms(100);
}

return 0;
}
/// \end::hello_rtc_main[]
2 changes: 0 additions & 2 deletions rtc/rtc_alarm_repeat/rtc_alarm_repeat.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,4 @@ int main() {

// Alarm will keep firing forever
while(1);

return 0;
}
2 changes: 0 additions & 2 deletions spi/bme280_spi/bme280_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,5 @@ int main() {

sleep_ms(1000);
}

return 0;
#endif
}
11 changes: 0 additions & 11 deletions spi/max7219_32x8_spi/max7219_32x8_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,6 @@ static inline void cs_deselect() {
#endif

#if defined(spi_default) && defined(PICO_DEFAULT_SPI_CSN_PIN)
static void write_register(uint8_t reg, uint8_t data) {
uint8_t buf[2];
buf[0] = reg;
buf[1] = data;
cs_select();
spi_write_blocking(spi_default, buf, 2);
cs_deselect();
sleep_ms(1);
}

static void write_register_all(uint8_t reg, uint8_t data) {
uint8_t buf[2];
Expand Down Expand Up @@ -135,7 +126,5 @@ int main() {

bright++;
}

return 0;
#endif
}
Loading