diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2017-09-22 18:05:51 -0700 |
|---|---|---|
| committer | Dan Halbert <halbert@halwitz.org> | 2017-09-22 21:05:51 -0400 |
| commit | 6839fff31303463d5c7942387fa498895edf1abf (patch) | |
| tree | f4c5b94c6534c8d5c65ea6b7209cd2d681508f5f /atmel-samd/asf4/samd21/examples | |
| parent | 3ad01ddb04b160b74b4baee9fce043da17dbcef5 (diff) | |
Move to ASF4 and introduce SAMD51 support. (#258)3.0.0-alpha.0
* atmel-samd: Remove ASF3. This will break builds.
* atmel-samd: Add ASF4 for the SAMD21 and SAMD51.
* Introduce the supervisor concept to facilitate porting.
The supervisor is the code which runs individual MicroPython VMs. By
splitting it out we make it more consistent and easier to find.
This also adds very basic SAMD21 and SAMD51 support using the
supervisor. Only the REPL currently works.
This begins the work for #178.
Diffstat (limited to 'atmel-samd/asf4/samd21/examples')
| -rw-r--r-- | atmel-samd/asf4/samd21/examples/driver_examples.c | 140 | ||||
| -rw-r--r-- | atmel-samd/asf4/samd21/examples/driver_examples.h | 32 |
2 files changed, 172 insertions, 0 deletions
diff --git a/atmel-samd/asf4/samd21/examples/driver_examples.c b/atmel-samd/asf4/samd21/examples/driver_examples.c new file mode 100644 index 000000000..9fb93dc3e --- /dev/null +++ b/atmel-samd/asf4/samd21/examples/driver_examples.c @@ -0,0 +1,140 @@ +/* + * Code generated from Atmel Start. + * + * This file will be overwritten when reconfiguring your Atmel Start project. + * Please copy examples or other code you want to keep to a separate file + * to avoid losing it when reconfiguring. + */ + +#include "driver_examples.h" +#include "driver_init.h" +#include "utils.h" + +/** + * Example of using ADC_0 to generate waveform. + */ +void ADC_0_example(void) +{ + uint8_t buffer[2]; + + adc_sync_enable_channel(&ADC_0, 0); + + while (1) { + adc_sync_read_channel(&ADC_0, 0, buffer, 2); + } +} + +static uint8_t src_data[128]; +static uint8_t chk_data[128]; +/** + * Example of using FLASH_0 to read and write buffer. + */ +void FLASH_0_example(void) +{ + uint32_t page_size; + uint16_t i; + + /* Init source data */ + page_size = flash_get_page_size(&FLASH_0); + + for (i = 0; i < page_size; i++) { + src_data[i] = i; + } + + /* Write data to flash */ + flash_write(&FLASH_0, 0x3200, src_data, page_size); + + /* Read data from flash */ + flash_read(&FLASH_0, 0x3200, chk_data, page_size); +} + +/** + * Example of using SPI_0 to write "Hello World" using the IO abstraction. + */ +static uint8_t example_SPI_0[12] = "Hello World!"; + +void SPI_0_example(void) +{ + struct io_descriptor *io; + spi_m_sync_get_io_descriptor(&SPI_0, &io); + + spi_m_sync_enable(&SPI_0); + io_write(io, example_SPI_0, 12); +} + +void I2C_0_example(void) +{ + struct io_descriptor *I2C_0_io; + + i2c_m_sync_get_io_descriptor(&I2C_0, &I2C_0_io); + i2c_m_sync_enable(&I2C_0); + i2c_m_sync_set_slaveaddr(&I2C_0, 0x12, I2C_M_SEVEN); + io_write(I2C_0_io, (uint8_t *)"Hello World!", 12); +} + +/** + * Example of using USART_0 to write "Hello World" using the IO abstraction. + */ +void USART_0_example(void) +{ + struct io_descriptor *io; + usart_sync_get_io_descriptor(&USART_0, &io); + usart_sync_enable(&USART_0); + + io_write(io, (uint8_t *)"Hello World!", 12); +} + +void delay_example(void) +{ + delay_ms(5000); +} + +static struct timer_task TIMER_0_task1, TIMER_0_task2; +/** + * Example of using TIMER_0. + */ +static void TIMER_0_task1_cb(const struct timer_task *const timer_task) +{ +} + +static void TIMER_0_task2_cb(const struct timer_task *const timer_task) +{ +} + +void TIMER_0_example(void) +{ + TIMER_0_task1.interval = 100; + TIMER_0_task1.cb = TIMER_0_task1_cb; + TIMER_0_task1.mode = TIMER_TASK_REPEAT; + TIMER_0_task2.interval = 200; + TIMER_0_task2.cb = TIMER_0_task2_cb; + TIMER_0_task2.mode = TIMER_TASK_REPEAT; + + timer_add_task(&TIMER_0, &TIMER_0_task1); + timer_add_task(&TIMER_0, &TIMER_0_task2); + timer_start(&TIMER_0); +} + +/** + * Example of using PWM_0. + */ +void PWM_0_example(void) +{ + pwm_set_parameters(&PWM_0, 10000, 5000); + pwm_enable(&PWM_0); +} + +/** + * Example of using DAC_0 to generate waveform. + */ +void DAC_0_example(void) +{ + uint16_t i = 0; + + dac_sync_enable_channel(&DAC_0, 0); + + for (;;) { + dac_sync_write(&DAC_0, 0, &i, 1); + i = (i + 1) % 1024; + } +} diff --git a/atmel-samd/asf4/samd21/examples/driver_examples.h b/atmel-samd/asf4/samd21/examples/driver_examples.h new file mode 100644 index 000000000..7a4353b98 --- /dev/null +++ b/atmel-samd/asf4/samd21/examples/driver_examples.h @@ -0,0 +1,32 @@ +/* + * Code generated from Atmel Start. + * + * This file will be overwritten when reconfiguring your Atmel Start project. + * Please copy examples or other code you want to keep to a separate file + * to avoid losing it when reconfiguring. + */ +#ifndef DRIVER_EXAMPLES_H_INCLUDED +#define DRIVER_EXAMPLES_H_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +void ADC_0_example(void); + +void FLASH_0_example(void); + +void I2C_0_example(void); + +void USART_0_example(void); + +void delay_example(void); + +void PWM_0_example(void); + +void DAC_0_example(void); + +#ifdef __cplusplus +} +#endif +#endif // DRIVER_EXAMPLES_H_INCLUDED |
