M adafruit-feather-m0-basic-template.hzp +2 -0
@@ 45,6 45,8 @@
<file file_name="targets/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/numeric_utils.h" />
<file file_name="targets/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_tc.c" />
<file file_name="targets/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_tc.h" />
+ <file file_name="targets/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_adc.c" />
+ <file file_name="targets/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_adc.h" />
</folder>
</project>
</solution>
M targets/Adafruit_Feather_M0_Basic/ctl_board.c +19 -5
@@ 147,26 147,40 @@ ctl_board_init(void)
d21_spi_set_pin_config(adafruit_m0_spis, ADAFRUIT_M0_SPI_AMOUNT);
d2x_eic_init();
- d21_configure_i2c1_bus();
+ // SCL & SDA pins on the Feather board.
+ d21_configure_i2c_bus(3, 100000);
+ // Polled uart0, pins 0 (RX) and 1 (TX) on Feather M0
uart = d21_uart(0);
-
ctl_uart_init(uart, NULL, NULL);
ctl_uart_set_baud(uart, 9600);
ctl_uart_puts(uart, "board initialized\r\n");
- gpio_set_output(D2X_PORT_A, 17); // LED
+ gpio_set_output(LED_PORT, LED_PIN); // LED
}
+static void button_press(uint8_t int_no, void *user_data)
+{
+ (void)int_no;
+ CTL_ISR_FN_t isr = (CTL_ISR_FN_t)user_data;
+ isr();
+}
+
+/* Adafruit Feather M0 Basic does not have buttons, but
+ * Oled wing has buttons A, B, and C. Button C is connected
+ * to pin D5 (PA15/EXTINT15).
+ */
void
ctl_board_on_button_pressed(CTL_ISR_FN_t isr)
{
+ gpio_set_extint(SAMD_PORT(ARDUINO_D5), SAMD_PIN(ARDUINO_D5), false);
+ d2x_eic_enable_int(15, false, SENSE_EDGE_FALLING, button_press, isr);
}
void
ctl_board_set_leds(unsigned v)
{
- gpio_set_state(D2X_PORT_A, 17, v != 0);
+ gpio_set_state(LED_PORT, LED_PIN, v != 0);
}
unsigned long
@@ 175,7 189,7 @@ platform_cpu_tick(void)
return ctl_get_current_time();
}
-
+/* Note, these spin delays are not accurate */
void
platform_spin_delay_cycles(unsigned long cycles)
{
M targets/Adafruit_Feather_M0_Basic/m0_main_ctl.c +10 -11
@@ 29,25 29,24 @@
#include "libdevice/ctl_uart.h"
#include "platform_atmel_d21_uart.h"
-CTL_TASK_t main_task, new_task;
+CTL_TASK_t main_task, led_task;
-#define CALLSTACKSIZE 16 // this is only required for AVR builds
#define STACKSIZE 64
-unsigned new_task_stack[1+STACKSIZE+1];
+unsigned led_task_stack[1+STACKSIZE+1];
void
-new_task_code(void *p)
+led_task_code(void *p)
{
unsigned int v=0;
CTL_UART_t *uart = d21_uart(0);
- ctl_uart_puts(uart, "new_task_code started\r\n");
+ ctl_uart_puts(uart, "led_task_code started\r\n");
while (1)
{
// task logic goes here
v++;
ctl_board_set_leds(v % 2);
- ctl_timeout_wait(ctl_get_current_time() + ctl_get_ticks_per_second()*10);
+ ctl_timeout_wait(ctl_get_current_time() + ctl_get_ticks_per_second() * 3);
}
}
@@ 66,14 65,14 @@ int main(void)
ctl_board_init();
ctl_board_set_leds(1);
- memset(new_task_stack, 0xcd, sizeof(new_task_stack)); // write known values into the stack
- new_task_stack[0]=new_task_stack[1+STACKSIZE]=0xfacefeed; // put marker values at the words before/after the stack
- ctl_task_run(&new_task, 1, new_task_code, 0, "new_task", STACKSIZE, new_task_stack+1, CALLSTACKSIZE);
+ memset(led_task_stack, 0xcd, sizeof(led_task_stack)); // write known values into the stack
+ led_task_stack[0]=led_task_stack[1+STACKSIZE]=0xfacefeed; // put marker values at the words before/after the stack
+ ctl_task_run(&led_task, 1, led_task_code, 0, "led_task", STACKSIZE, led_task_stack+1, 0);
ctl_task_set_priority(&main_task, 0); // drop to lowest priority to start created tasks running.
while (1)
{
- // power down can go here if supported
- v++;
+ // tickless idle mode
+ ctl_sleep(ctl_get_sleep_delay());
}
return 0;
}
M targets/Adafruit_Feather_M0_Basic/project_templates_Adafruit_Feather_M0_Basic.xml +2 -0
@@ 189,6 189,8 @@
<file name="$(TargetsDir)/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_gpio.c" expand="no"/>
<file name="$(TargetsDir)/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_eic.h" expand="no"/>
<file name="$(TargetsDir)/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_eic.c" expand="no"/>
+ <file name="$(TargetsDir)/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_adc.h" expand="no"/>
+ <file name="$(TargetsDir)/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_adc.c" expand="no"/>
<file name="$(TargetsDir)/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_rtc.h" expand="no"/>
<file name="$(TargetsDir)/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_rtc.c" expand="no"/>
<file name="$(TargetsDir)/Adafruit_Feather_M0_Basic/samd2x-peripheral-lib/d2x_tc.c" expand="no"/>