aboutsummaryrefslogtreecommitdiff
path: root/atmel-samd/common-hal
diff options
context:
space:
mode:
Diffstat (limited to 'atmel-samd/common-hal')
-rw-r--r--atmel-samd/common-hal/analogio/AnalogIn.h7
-rw-r--r--atmel-samd/common-hal/audioio/AudioOut.h1
-rw-r--r--atmel-samd/common-hal/digitalio/DigitalInOut.c65
-rw-r--r--atmel-samd/common-hal/microcontroller/Pin.c88
-rw-r--r--atmel-samd/common-hal/microcontroller/Pin.h30
-rw-r--r--atmel-samd/common-hal/microcontroller/Processor.c292
-rw-r--r--atmel-samd/common-hal/microcontroller/__init__.c25
-rw-r--r--atmel-samd/common-hal/pulseio/PWMOut.h2
-rw-r--r--atmel-samd/common-hal/pulseio/PulseOut.h2
-rw-r--r--atmel-samd/common-hal/usb_hid/types.h2
10 files changed, 246 insertions, 268 deletions
diff --git a/atmel-samd/common-hal/analogio/AnalogIn.h b/atmel-samd/common-hal/analogio/AnalogIn.h
index 3e9ddd76e..7c988d909 100644
--- a/atmel-samd/common-hal/analogio/AnalogIn.h
+++ b/atmel-samd/common-hal/analogio/AnalogIn.h
@@ -29,13 +29,6 @@
#include "common-hal/microcontroller/Pin.h"
-// Don't reorder these includes because they are dependencies of adc_feature.h.
-// They should really be included by adc_feature.h.
-#include <compiler.h>
-#include "asf/sam0/drivers/system/clock/gclk.h"
-#include "asf/sam0/utils/cmsis/samd21/include/component/adc.h"
-#include "asf/sam0/drivers/adc/adc_sam_d_r/adc_feature.h"
-
#include "py/obj.h"
typedef struct {
diff --git a/atmel-samd/common-hal/audioio/AudioOut.h b/atmel-samd/common-hal/audioio/AudioOut.h
index 738a2aa6c..78e4ffc77 100644
--- a/atmel-samd/common-hal/audioio/AudioOut.h
+++ b/atmel-samd/common-hal/audioio/AudioOut.h
@@ -28,7 +28,6 @@
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_AUDIOIO_AUDIOOUT_H
#include "common-hal/microcontroller/Pin.h"
-#include "asf/sam0/drivers/tc/tc.h"
#include "extmod/vfs_fat_file.h"
#include "py/obj.h"
diff --git a/atmel-samd/common-hal/digitalio/DigitalInOut.c b/atmel-samd/common-hal/digitalio/DigitalInOut.c
index 3f178fac0..37a4f7096 100644
--- a/atmel-samd/common-hal/digitalio/DigitalInOut.c
+++ b/atmel-samd/common-hal/digitalio/DigitalInOut.c
@@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
- * Copyright (c) 2013, 2014 Damien P. George
+ * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -31,23 +31,18 @@
#include "py/runtime.h"
#include "py/mphal.h"
+#include "hal/include/hal_gpio.h"
+
#include "common-hal/microcontroller/Pin.h"
#include "shared-bindings/digitalio/DigitalInOut.h"
-#include "asf/sam0/drivers/port/port.h"
-#include "asf/sam0/drivers/system/pinmux/pinmux.h"
-
digitalinout_result_t common_hal_digitalio_digitalinout_construct(
digitalio_digitalinout_obj_t* self, const mcu_pin_obj_t* pin) {
claim_pin(pin);
self->pin = pin;
- struct port_config pin_conf;
- port_get_config_defaults(&pin_conf);
-
- pin_conf.direction = PORT_PIN_DIR_INPUT;
- pin_conf.input_pull = PORT_PIN_PULL_NONE;
- port_pin_set_config(self->pin->pin, &pin_conf);
+ gpio_set_pin_pull_mode(pin->pin, GPIO_PULL_OFF);
+ gpio_set_pin_direction(pin->pin, GPIO_DIRECTION_IN);
return DIGITALINOUT_OK;
}
@@ -65,12 +60,8 @@ void common_hal_digitalio_digitalinout_switch_to_input(
void common_hal_digitalio_digitalinout_switch_to_output(
digitalio_digitalinout_obj_t* self, bool value,
enum digitalio_drive_mode_t drive_mode) {
- struct port_config pin_conf;
- port_get_config_defaults(&pin_conf);
-
- pin_conf.direction = PORT_PIN_DIR_INPUT;
- pin_conf.input_pull = PORT_PIN_PULL_NONE;
- port_pin_set_config(self->pin->pin, &pin_conf);
+ gpio_set_pin_pull_mode(self->pin->pin, GPIO_PULL_OFF);
+ gpio_set_pin_direction(self->pin->pin, GPIO_DIRECTION_OUT);
self->output = true;
self->open_drain = drive_mode == DRIVE_MODE_OPEN_DRAIN;
@@ -84,36 +75,29 @@ enum digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(
void common_hal_digitalio_digitalinout_set_value(
digitalio_digitalinout_obj_t* self, bool value) {
- uint32_t pin = self->pin->pin;
- PortGroup *const port_base = port_get_group_from_gpio_pin(pin);
- uint32_t pin_mask = (1UL << (pin % 32));
-
- /* Set the pin to high or low atomically based on the requested level */
if (value) {
if (self->open_drain) {
- port_base->DIRCLR.reg = pin_mask;
+ gpio_set_pin_direction(self->pin->pin, GPIO_DIRECTION_IN);
} else {
- port_base->DIRSET.reg = pin_mask;
- port_base->OUTSET.reg = pin_mask;
+ gpio_set_pin_level(self->pin->pin, true);
+ gpio_set_pin_direction(self->pin->pin, GPIO_DIRECTION_OUT);
}
} else {
- port_base->DIRSET.reg = pin_mask;
- port_base->OUTCLR.reg = pin_mask;
+ gpio_set_pin_level(self->pin->pin, false);
+ gpio_set_pin_direction(self->pin->pin, GPIO_DIRECTION_OUT);
}
}
bool common_hal_digitalio_digitalinout_get_value(
digitalio_digitalinout_obj_t* self) {
uint32_t pin = self->pin->pin;
- PortGroup *const port_base = port_get_group_from_gpio_pin(pin);
- uint32_t pin_mask = (1UL << (pin % 32));
if (!self->output) {
- return (port_base->IN.reg & pin_mask);
+ return gpio_get_pin_level(self->pin->pin);
} else {
- if (self->open_drain && (port_base->DIR.reg & pin_mask) == 0) {
+ if (self->open_drain && hri_port_get_DIR_reg(PORT, (enum gpio_port)GPIO_PORT(pin), 1U << pin) == 0) {
return true;
} else {
- return (port_base->OUT.reg & pin_mask);
+ return hri_port_get_OUT_reg(PORT, (enum gpio_port)GPIO_PORT(pin), 1U << pin);
}
}
}
@@ -141,38 +125,31 @@ enum digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
void common_hal_digitalio_digitalinout_set_pull(
digitalio_digitalinout_obj_t* self, enum digitalio_pull_t pull) {
- enum port_pin_pull asf_pull = PORT_PIN_PULL_NONE;
+ enum gpio_pull_mode asf_pull = GPIO_PULL_OFF;
switch (pull) {
case PULL_UP:
- asf_pull = PORT_PIN_PULL_UP;
+ asf_pull = GPIO_PULL_UP;
break;
case PULL_DOWN:
- asf_pull = PORT_PIN_PULL_DOWN;
+ asf_pull = GPIO_PULL_DOWN;
break;
case PULL_NONE:
default:
break;
}
- struct port_config pin_conf;
- port_get_config_defaults(&pin_conf);
-
- pin_conf.direction = PORT_PIN_DIR_INPUT;
- pin_conf.input_pull = asf_pull;
- port_pin_set_config(self->pin->pin, &pin_conf);
+ gpio_set_pin_pull_mode(self->pin->pin, asf_pull);
}
enum digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(
digitalio_digitalinout_obj_t* self) {
uint32_t pin = self->pin->pin;
- PortGroup *const port_base = port_get_group_from_gpio_pin(pin);
- uint32_t pin_mask = (1UL << (pin % 32));
if (self->output) {
mp_raise_AttributeError("Cannot get pull while in output mode");
return PULL_NONE;
} else {
- if (port_base->PINCFG[pin % 32].bit.PULLEN == 0) {
+ if (hri_port_get_PINCFG_PULLEN_bit(PORT, (enum gpio_port)GPIO_PORT(pin), pin) == 0) {
return PULL_NONE;
- } if ((port_base->OUT.reg & pin_mask) > 0) {
+ } if (hri_port_get_OUT_reg(PORT, (enum gpio_port)GPIO_PORT(pin), 1U << pin) > 0) {
return PULL_UP;
} else {
return PULL_DOWN;
diff --git a/atmel-samd/common-hal/microcontroller/Pin.c b/atmel-samd/common-hal/microcontroller/Pin.c
index d814eb89c..a7b494940 100644
--- a/atmel-samd/common-hal/microcontroller/Pin.c
+++ b/atmel-samd/common-hal/microcontroller/Pin.c
@@ -26,10 +26,16 @@
#include "shared-bindings/microcontroller/Pin.h"
-#include "asf/sam0/drivers/port/port.h"
+#include "atmel_start_pins.h"
+#include "hal/include/hal_gpio.h"
-#include "rgb_led_status.h"
+#include "supervisor/shared/rgb_led_status.h"
+#ifdef SAMD21
#include "samd21_pins.h"
+#endif
+#ifdef SAMD51
+#include "samd51_pins.h"
+#endif
#ifdef MICROPY_HW_NEOPIXEL
bool neopixel_in_use;
@@ -43,22 +49,39 @@ bool speaker_enable_in_use;
#endif
void reset_all_pins(void) {
- struct system_pinmux_config config;
- system_pinmux_get_config_defaults(&config);
- config.powersave = true;
-
- uint32_t pin_mask[2] = PORT_OUT_IMPLEMENTED;
+ uint32_t pin_mask[PORT_BITS / 32 + 1] = PORT_OUT_IMPLEMENTED;
// Do not full reset USB or SWD lines.
- pin_mask[0] &= ~(PORT_PA24 | PORT_PA25 | PORT_PA30 | PORT_PA31);
+ pin_mask[0] &= ~(PORT_PA24 | PORT_PA25 | PORT_PA30);
- system_pinmux_group_set_config(&(PORT->Group[0]), pin_mask[0] & ~MICROPY_PORT_A, &config);
- system_pinmux_group_set_config(&(PORT->Group[1]), pin_mask[1] & ~MICROPY_PORT_B, &config);
+ // The SWO pin changes between the 21 and 51.
+ #ifdef PORT_PB30H_CM4_SWO
+ pin_mask[1] &= ~(PORT_PB30);
+ #else
+ pin_mask[0] &= ~(PORT_PA31);
+ #endif
+
+ //gpio_set_port_direction(GPIO_PORTA, pin_mask[0] & ~MICROPY_PORT_A, GPIO_DIRECTION_OFF);
+ gpio_set_port_direction(GPIO_PORTB, pin_mask[1] & ~MICROPY_PORT_B, GPIO_DIRECTION_OFF);
+ #if PORT_BITS > 64
+ gpio_set_port_direction(GPIO_PORTC, pin_mask[2] & ~MICROPY_PORT_C, GPIO_DIRECTION_OFF);
+ #endif
+ #if PORT_BITS > 96
+ gpio_set_port_direction(GPIO_PORTD, pin_mask[3] & ~MICROPY_PORT_D, GPIO_DIRECTION_OFF);
+ #endif
// Configure SWD
- system_pinmux_get_config_defaults(&config);
- config.mux_position = 0x6;
- system_pinmux_group_set_config(&(PORT->Group[0]), PORT_PA30 | PORT_PA31, &config);
+ gpio_set_pin_direction(PIN_PA30, GPIO_DIRECTION_OUT);
+ #ifdef SAMD51
+ gpio_set_pin_function(PIN_PB30, MUX_PB30H_CM4_SWO);
+ gpio_set_pin_direction(PIN_PB30, GPIO_DIRECTION_OUT);
+ gpio_set_pin_function(PIN_PB30, MUX_PB30H_CM4_SWO);
+ #endif
+ #ifdef SAMD21
+ //gpio_set_pin_function(PIN_PA30, GPIO_PIN_FUNCTION_G);
+ //gpio_set_pin_direction(PIN_PA31, GPIO_DIRECTION_OUT);
+ //gpio_set_pin_function(PIN_PA31, GPIO_PIN_FUNCTION_G);
+ #endif
#ifdef MICROPY_HW_NEOPIXEL
neopixel_in_use = false;
@@ -71,12 +94,9 @@ void reset_all_pins(void) {
// After configuring SWD because it may be shared.
#ifdef SPEAKER_ENABLE_PIN
speaker_enable_in_use = false;
- struct port_config pin_conf;
- port_get_config_defaults(&pin_conf);
-
- pin_conf.direction = PORT_PIN_DIR_OUTPUT;
- port_pin_set_config(SPEAKER_ENABLE_PIN->pin, &pin_conf);
- port_pin_set_output_level(SPEAKER_ENABLE_PIN->pin, false);
+ gpio_set_pin_function(SPEAKER_ENABLE_PIN->pin, GPIO_PIN_FUNCTION_OFF);
+ gpio_set_pin_direction(SPEAKER_ENABLE_PIN->pin, GPIO_DIRECTION_OUT);
+ gpio_set_pin_level(SPEAKER_ENABLE_PIN->pin, false);
#endif
}
@@ -104,24 +124,26 @@ void reset_pin(uint8_t pin) {
}
#endif
- struct system_pinmux_config config;
- system_pinmux_get_config_defaults(&config);
- if (pin == PIN_PA30 || pin == PIN_PA31) {
- config.mux_position = 0x6;
+ if (pin == PIN_PA30
+ #ifdef SAMD51
+ || pin == PIN_PB30) {
+ gpio_set_pin_function(pin, GPIO_PIN_FUNCTION_H);
+ #endif
+ #ifdef SAMD21
+ || pin == PIN_PA31) {
+ gpio_set_pin_function(pin, GPIO_PIN_FUNCTION_G);
+ #endif
} else {
- config.powersave = true;
+ gpio_set_pin_direction(pin, GPIO_DIRECTION_OFF);
+ gpio_set_pin_function(pin, GPIO_PIN_FUNCTION_OFF);
}
- system_pinmux_pin_set_config(pin, &config);
#ifdef SPEAKER_ENABLE_PIN
if (pin == SPEAKER_ENABLE_PIN->pin) {
speaker_enable_in_use = false;
- struct port_config pin_conf;
- port_get_config_defaults(&pin_conf);
-
- pin_conf.direction = PORT_PIN_DIR_OUTPUT;
- port_pin_set_config(SPEAKER_ENABLE_PIN->pin, &pin_conf);
- port_pin_set_output_level(SPEAKER_ENABLE_PIN->pin, false);
+ gpio_set_pin_function(pin, GPIO_PIN_FUNCTION_OFF);
+ gpio_set_pin_direction(SPEAKER_ENABLE_PIN->pin, GPIO_DIRECTION_OUT);
+ gpio_set_pin_level(SPEAKER_ENABLE_PIN->pin, false);
}
#endif
}
@@ -169,8 +191,8 @@ bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t* pin) {
}
#endif
- PortGroup *const port = system_pinmux_get_group_from_gpio_pin(pin->pin);
- uint32_t pin_index = (pin->pin);
+ PortGroup *const port = &PORT->Group[(enum gpio_port)GPIO_PORT(pin->pin)];
+ uint8_t pin_index = GPIO_PIN(pin->pin);
volatile PORT_PINCFG_Type *state = &port->PINCFG[pin_index];
volatile PORT_PMUX_Type *pmux = &port->PMUX[pin_index / 2];
diff --git a/atmel-samd/common-hal/microcontroller/Pin.h b/atmel-samd/common-hal/microcontroller/Pin.h
index 31c083311..154ea1e47 100644
--- a/atmel-samd/common-hal/microcontroller/Pin.h
+++ b/atmel-samd/common-hal/microcontroller/Pin.h
@@ -27,17 +27,11 @@
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_MICROCONTROLLER_PIN_H
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_MICROCONTROLLER_PIN_H
-// Don't reorder these includes because they are dependencies of adc_feature.h.
-// They should really be included by adc_feature.h.
-#include "compiler.h"
-#include "asf/sam0/drivers/system/clock/gclk.h"
-#include "asf/sam0/utils/cmsis/samd21/include/component/adc.h"
-#include "asf/sam0/drivers/adc/adc_sam_d_r/adc_feature.h" // for adc_positive_input
+#include "py/obj.h"
-#include "asf/sam0/drivers/tc/tc.h"
-#include "asf/sam0/drivers/tcc/tcc.h"
+#include "mpconfigport.h"
-#include "py/obj.h"
+#include "include/component/sercom.h"
typedef struct {
Sercom *const sercom;
@@ -49,24 +43,32 @@ typedef struct {
Tc *const tc;
Tcc *const tcc;
};
+ #ifdef SAMD21
bool is_tc:1;
- uint8_t channel:3;
+ #endif
uint8_t wave_output:4;
} pin_timer_t;
+#ifdef SAMD21
+ #define NUM_TIMERS_PER_PIN 2
+ #define NUM_ADC_PER_PIN 1
+#endif
+#ifdef SAMD51
+ #define NUM_TIMERS_PER_PIN 3
+ #define NUM_ADC_PER_PIN 2
+#endif
#define NUM_SERCOMS_PER_PIN 2
+
typedef struct {
mp_obj_base_t base;
qstr name;
uint8_t pin;
bool has_extint:1;
uint8_t extint_channel:7;
- bool has_adc:1;
- enum adc_positive_input adc_input:7;
bool has_touch:1;
uint8_t touch_y_line:7; // 0 - 15. Assumed to be Y channel.
- pin_timer_t primary_timer;
- pin_timer_t secondary_timer;
+ uint8_t adc_input[NUM_ADC_PER_PIN];
+ pin_timer_t timer[NUM_TIMERS_PER_PIN];
pin_sercom_t sercom[NUM_SERCOMS_PER_PIN];
} mcu_pin_obj_t;
diff --git a/atmel-samd/common-hal/microcontroller/Processor.c b/atmel-samd/common-hal/microcontroller/Processor.c
index c398c5e6f..a037c42db 100644
--- a/atmel-samd/common-hal/microcontroller/Processor.c
+++ b/atmel-samd/common-hal/microcontroller/Processor.c
@@ -63,175 +63,169 @@
#include "common-hal/microcontroller/Processor.h"
-// Don't reorder these includes because they are dependencies of adc_feature.h.
-// They should really be included by adc_feature.h.
-#include <compiler.h>
-#include "asf/sam0/drivers/system/clock/gclk.h"
-#include "asf/sam0/utils/cmsis/samd21/include/component/adc.h"
-#include "asf/sam0/drivers/adc/adc_sam_d_r/adc_feature.h"
-#include "asf/sam0/drivers/adc/adc.h"
-
-#define ADC_TEMP_SAMPLE_LENGTH 4
-#define INT1V_VALUE_FLOAT 1.0
-#define INT1V_DIVIDER_1000 1000.0
-#define ADC_12BIT_FULL_SCALE_VALUE_FLOAT 4095.0
-
-typedef struct nvm_calibration_data_t {
- float tempR; // Production Room temperature
- float tempH; // Production Hot temperature
- float INT1VR; // Room temp 2's complement of the internal 1V reference value
- float INT1VH; // Hot temp 2's complement of the internal 1V reference value
- uint16_t ADCR; // Production Room temperature ADC value
- uint16_t ADCH; // Production Hot temperature ADC value
- float VADCR; // Room temperature ADC voltage
- float VADCH; // Hot temperature ADC voltage
-} nvm_calibration_data_t;
+// #define ADC_TEMP_SAMPLE_LENGTH 4
+// #define INT1V_VALUE_FLOAT 1.0
+// #define INT1V_DIVIDER_1000 1000.0
+// #define ADC_12BIT_FULL_SCALE_VALUE_FLOAT 4095.0
+//
+// typedef struct nvm_calibration_data_t {
+// float tempR; // Production Room temperature
+// float tempH; // Production Hot temperature
+// float INT1VR; // Room temp 2's complement of the internal 1V reference value
+// float INT1VH; // Hot temp 2's complement of the internal 1V reference value
+// uint16_t ADCR; // Production Room temperature ADC value
+// uint16_t ADCH; // Production Hot temperature ADC value
+// float VADCR; // Room temperature ADC voltage
+// float VADCH; // Hot temperature ADC voltage
+// } nvm_calibration_data_t;
// Decimal to fraction conversion. (adapted from ASF sample).
-STATIC float convert_dec_to_frac(uint8_t val) {
- float float_val = (float)val;
- if (val < 10) {
- return (float_val/10.0);
- } else if (val < 100) {
- return (float_val/100.0);
- } else {
- return (float_val/1000.0);
- }
-}
-
-STATIC void configure_adc_temp(struct adc_module *adc_instance) {
- struct adc_config config_adc;
- adc_get_config_defaults(&config_adc);
-
- // The parameters chosen here are from the temperature example in:
- // http://www.atmel.com/images/Atmel-42645-ADC-Configurations-with-Examples_ApplicationNote_AT11481.pdf
- // That note also recommends in general:
- // "Discard the first conversion result whenever there is a change
- // in ADC configuration like voltage reference / ADC channel change."
-
- config_adc.clock_prescaler = ADC_CLOCK_PRESCALER_DIV16;
- config_adc.reference = ADC_REFERENCE_INT1V;
- config_adc.positive_input = ADC_POSITIVE_INPUT_TEMP;
- config_adc.negative_input = ADC_NEGATIVE_INPUT_GND;
- config_adc.sample_length = ADC_TEMP_SAMPLE_LENGTH;
-
- adc_init(adc_instance, ADC, &config_adc);
-
- // Oversample and decimate. A higher samplenum produces a more stable result.
- ADC->AVGCTRL.reg = ADC_AVGCTRL_ADJRES(2) | ADC_AVGCTRL_SAMPLENUM_4;
- //ADC->AVGCTRL.reg = ADC_AVGCTRL_ADJRES(4) | ADC_AVGCTRL_SAMPLENUM_16;
-}
+// STATIC float convert_dec_to_frac(uint8_t val) {
+// float float_val = (float)val;
+// if (val < 10) {
+// return (float_val/10.0);
+// } else if (val < 100) {
+// return (float_val/100.0);
+// } else {
+// return (float_val/1000.0);
+// }
+// }
+
+// STATIC void configure_adc_temp(struct adc_module *adc_instance) {
+// struct adc_config config_adc;
+// adc_get_config_defaults(&config_adc);
+//
+// // The parameters chosen here are from the temperature example in:
+// // http://www.atmel.com/images/Atmel-42645-ADC-Configurations-with-Examples_ApplicationNote_AT11481.pdf
+// // That note also recommends in general:
+// // "Discard the first conversion result whenever there is a change
+// // in ADC configuration like voltage reference / ADC channel change."
+//
+// config_adc.clock_prescaler = ADC_CLOCK_PRESCALER_DIV16;
+// config_adc.reference = ADC_REFERENCE_INT1V;
+// config_adc.positive_input = ADC_POSITIVE_INPUT_TEMP;
+// config_adc.negative_input = ADC_NEGATIVE_INPUT_GND;
+// config_adc.sample_length = ADC_TEMP_SAMPLE_LENGTH;
+//
+// adc_init(adc_instance, ADC, &config_adc);
+//
+// // Oversample and decimate. A higher samplenum produces a more stable result.
+// ADC->AVGCTRL.reg = ADC_AVGCTRL_ADJRES(2) | ADC_AVGCTRL_SAMPLENUM_4;
+// //ADC->AVGCTRL.reg = ADC_AVGCTRL_ADJRES(4) | ADC_AVGCTRL_SAMPLENUM_16;
+// }
// Extract the production calibration data information from NVM (adapted from ASF sample).
//
-STATIC void load_calibration_data(nvm_calibration_data_t *cal) {
- volatile uint32_t val1; /* Temperature Log Row Content first 32 bits */
- volatile uint32_t val2; /* Temperature Log Row Content another 32 bits */
- uint8_t room_temp_val_int; /* Integer part of room temperature in °C */
- uint8_t room_temp_val_dec; /* Decimal part of room temperature in °C */
- uint8_t hot_temp_val_int; /* Integer part of hot temperature in °C */
- uint8_t hot_temp_val_dec; /* Decimal part of hot temperature in °C */
- int8_t room_int1v_val; /* internal 1V reference drift at room temperature */
- int8_t hot_int1v_val; /* internal 1V reference drift at hot temperature*/
-
- uint32_t *temp_log_row_ptr = (uint32_t *)NVMCTRL_TEMP_LOG;
-
- val1 = *temp_log_row_ptr;
- temp_log_row_ptr++;
- val2 = *temp_log_row_ptr;
-
- room_temp_val_int = (uint8_t)((val1 & NVMCTRL_FUSES_ROOM_TEMP_VAL_INT_Msk) >> NVMCTRL_FUSES_ROOM_TEMP_VAL_INT_Pos);
- room_temp_val_dec = (uint8_t)((val1 & NVMCTRL_FUSES_ROOM_TEMP_VAL_DEC_Msk) >> NVMCTRL_FUSES_ROOM_TEMP_VAL_DEC_Pos);
-
- hot_temp_val_int = (uint8_t)((val1 & NVMCTRL_FUSES_HOT_TEMP_VAL_INT_Msk) >> NVMCTRL_FUSES_HOT_TEMP_VAL_INT_Pos);
- hot_temp_val_dec = (uint8_t)((val1 & NVMCTRL_FUSES_HOT_TEMP_VAL_DEC_Msk) >> NVMCTRL_FUSES_HOT_TEMP_VAL_DEC_Pos);
-
- room_int1v_val = (int8_t)((val1 & NVMCTRL_FUSES_ROOM_INT1V_VAL_Msk) >> NVMCTRL_FUSES_ROOM_INT1V_VAL_Pos);
- hot_int1v_val = (int8_t)((val2 & NVMCTRL_FUSES_HOT_INT1V_VAL_Msk) >> NVMCTRL_FUSES_HOT_INT1V_VAL_Pos);
-
- cal->ADCR = (uint16_t)((val2 & NVMCTRL_FUSES_ROOM_ADC_VAL_Msk) >> NVMCTRL_FUSES_ROOM_ADC_VAL_Pos);
-
- cal->ADCH = (uint16_t)((val2 & NVMCTRL_FUSES_HOT_ADC_VAL_Msk) >> NVMCTRL_FUSES_HOT_ADC_VAL_Pos);
-
- cal->tempR = room_temp_val_int + convert_dec_to_frac(room_temp_val_dec);
- cal->tempH = hot_temp_val_int + convert_dec_to_frac(hot_temp_val_dec);
-
- cal->INT1VR = 1 - ((float)room_int1v_val/INT1V_DIVIDER_1000);
- cal->INT1VH = 1 - ((float)hot_int1v_val/INT1V_DIVIDER_1000);
-
- cal->VADCR = ((float)cal->ADCR * cal->INT1VR)/ADC_12BIT_FULL_SCALE_VALUE_FLOAT;
- cal->VADCH = ((float)cal->ADCH * cal->INT1VH)/ADC_12BIT_FULL_SCALE_VALUE_FLOAT;
-}
+// STATIC void load_calibration_data(nvm_calibration_data_t *cal) {
+// volatile uint32_t val1; /* Temperature Log Row Content first 32 bits */
+// volatile uint32_t val2; /* Temperature Log Row Content another 32 bits */
+// uint8_t room_temp_val_int; /* Integer part of room temperature in °C */
+// uint8_t room_temp_val_dec; /* Decimal part of room temperature in °C */
+// uint8_t hot_temp_val_int; /* Integer part of hot temperature in °C */
+// uint8_t hot_temp_val_dec; /* Decimal part of hot temperature in °C */
+// int8_t room_int1v_val; /* internal 1V reference drift at room temperature */
+// int8_t hot_int1v_val; /* internal 1V reference drift at hot temperature*/
+//
+// uint32_t *temp_log_row_ptr = (uint32_t *)NVMCTRL_TEMP_LOG;
+//
+// val1 = *temp_log_row_ptr;
+// temp_log_row_ptr++;
+// val2 = *temp_log_row_ptr;
+//
+// room_temp_val_int = (uint8_t)((val1 & NVMCTRL_FUSES_ROOM_TEMP_VAL_INT_Msk) >> NVMCTRL_FUSES_ROOM_TEMP_VAL_INT_Pos);
+// room_temp_val_dec = (uint8_t)((val1 & NVMCTRL_FUSES_ROOM_TEMP_VAL_DEC_Msk) >> NVMCTRL_FUSES_ROOM_TEMP_VAL_DEC_Pos);
+//
+// hot_temp_val_int = (uint8_t)((val1 & NVMCTRL_FUSES_HOT_TEMP_VAL_INT_Msk) >> NVMCTRL_FUSES_HOT_TEMP_VAL_INT_Pos);
+// hot_temp_val_dec = (uint8_t)((val1 & NVMCTRL_FUSES_HOT_TEMP_VAL_DEC_Msk) >> NVMCTRL_FUSES_HOT_TEMP_VAL_DEC_Pos);
+//
+// room_int1v_val = (int8_t)((val1 & NVMCTRL_FUSES_ROOM_INT1V_VAL_Msk) >> NVMCTRL_FUSES_ROOM_INT1V_VAL_Pos);
+// hot_int1v_val = (int8_t)((val2 & NVMCTRL_FUSES_HOT_INT1V_VAL_Msk) >> NVMCTRL_FUSES_HOT_INT1V_VAL_Pos);
+//
+// cal->ADCR = (uint16_t)((val2 & NVMCTRL_FUSES_ROOM_ADC_VAL_Msk) >> NVMCTRL_FUSES_ROOM_ADC_VAL_Pos);
+//
+// cal->ADCH = (uint16_t)((val2 & NVMCTRL_FUSES_HOT_ADC_VAL_Msk) >> NVMCTRL_FUSES_HOT_ADC_VAL_Pos);
+//
+// cal->tempR = room_temp_val_int + convert_dec_to_frac(room_temp_val_dec);
+// cal->tempH = hot_temp_val_int + convert_dec_to_frac(hot_temp_val_dec);
+//
+// cal->INT1VR = 1 - ((float)room_int1v_val/INT1V_DIVIDER_1000);
+// cal->INT1VH = 1 - ((float)hot_int1v_val/INT1V_DIVIDER_1000);
+//
+// cal->VADCR = ((float)cal->ADCR * cal->INT1VR)/ADC_12BIT_FULL_SCALE_VALUE_FLOAT;
+// cal->VADCH = ((float)cal->ADCH * cal->INT1VH)/ADC_12BIT_FULL_SCALE_VALUE_FLOAT;
+// }
/*
* Calculate fine temperature using Equation1 and Equation
* 1b as mentioned in data sheet section "Temperature Sensor Characteristics"
* of Electrical Characteristics. (adapted from ASF sample code).
*/
-STATIC float calculate_temperature(uint16_t raw_code, nvm_calibration_data_t *cal)
-{
- float VADC; /* Voltage calculation using ADC result for Coarse Temp calculation */
- float VADCM; /* Voltage calculation using ADC result for Fine Temp calculation. */
- float INT1VM; /* Voltage calculation for reality INT1V value during the ADC conversion */
-
- VADC = ((float)raw_code * INT1V_VALUE_FLOAT)/ADC_12BIT_FULL_SCALE_VALUE_FLOAT;
-
- // Hopefully compiler will remove common subepxressions here.
-
- /* Coarse Temp Calculation by assume INT1V=1V for this ADC conversion */
- float coarse_temp = cal->tempR + (((cal->tempH - cal->tempR)/(cal->VADCH - cal->VADCR)) * (VADC - cal->VADCR));
-
- /* Calculation to find the real INT1V value during the ADC conversion */
- INT1VM = cal->INT1VR + (((cal->INT1VH - cal->INT1VR) * (coarse_temp - cal->tempR))/(cal->tempH - cal->tempR));
-
- VADCM = ((float)raw_code * INT1VM)/ADC_12BIT_FULL_SCALE_VALUE_FLOAT;
-
- /* Fine Temp Calculation by replace INT1V=1V by INT1V = INT1Vm for ADC conversion */
- float fine_temp = cal->tempR + (((cal->tempH - cal->tempR)/(cal->VADCH - cal->VADCR)) * (VADCM - cal->VADCR));
-
- return fine_temp;
-}
+// STATIC float calculate_temperature(uint16_t raw_code, nvm_calibration_data_t *cal)
+// {
+// float VADC; /* Voltage calculation using ADC result for Coarse Temp calculation */
+// float VADCM; /* Voltage calculation using ADC result for Fine Temp calculation. */
+// float INT1VM; /* Voltage calculation for reality INT1V value during the ADC conversion */
+//
+// VADC = ((float)raw_code * INT1V_VALUE_FLOAT)/ADC_12BIT_FULL_SCALE_VALUE_FLOAT;
+//
+// // Hopefully compiler will remove common subepxressions here.
+//
+// /* Coarse Temp Calculation by assume INT1V=1V for this ADC conversion */
+// float coarse_temp = cal->tempR + (((cal->tempH - cal->tempR)/(cal->VADCH - cal->VADCR)) * (VADC - cal->VADCR));
+//
+// /* Calculation to find the real INT1V value during the ADC conversion */
+// INT1VM = cal->INT1VR + (((cal->INT1VH - cal->INT1VR) * (coarse_temp - cal->tempR))/(cal->tempH - cal->tempR));
+//
+// VADCM = ((float)raw_code * INT1VM)/ADC_12BIT_FULL_SCALE_VALUE_FLOAT;
+//
+// /* Fine Temp Calculation by replace INT1V=1V by INT1V = INT1Vm for ADC conversion */
+// float fine_temp = cal->tempR + (((cal->tempH - cal->tempR)/(cal->VADCH - cal->VADCR)) * (VADCM - cal->VADCR));
+//
+// return fine_temp;
+// }
// External interface.
//
float common_hal_mcu_processor_get_temperature(void) {
- struct adc_module adc_instance_struct;
-
- system_voltage_reference_enable(SYSTEM_VOLTAGE_REFERENCE_TEMPSENSE);
- configure_adc_temp(&adc_instance_struct);
- nvm_calibration_data_t nvm_calibration_data;
- load_calibration_data(&nvm_calibration_data);
-
- adc_enable(&adc_instance_struct);
-
- uint16_t data;
- enum status_code status;
-
- // Read twice and discard first result, as recommended in section 14 of
- // http://www.atmel.com/images/Atmel-42645-ADC-Configurations-with-Examples_ApplicationNote_AT11481.pdf
- // "Discard the first conversion result whenever there is a change in ADC configuration
- // like voltage reference / ADC channel change"
- // Empirical observation shows the first reading is quite different than subsequent ones.
-
- adc_start_conversion(&adc_instance_struct);
- do {
- status = adc_read(&adc_instance_struct, &data);
- } while (status == STATUS_BUSY);
-
- adc_start_conversion(&adc_instance_struct);
- do {
- status = adc_read(&adc_instance_struct, &data);
- } while (status == STATUS_BUSY);
-
- // Disable so that someone else can use the adc with different settings.
- adc_disable(&adc_instance_struct);
- return calculate_temperature(data, &nvm_calibration_data);
+ // struct adc_module adc_instance_struct;
+ //
+ // system_voltage_reference_enable(SYSTEM_VOLTAGE_REFERENCE_TEMPSENSE);
+ // configure_adc_temp(&adc_instance_struct);
+ // nvm_calibration_data_t nvm_calibration_data;
+ // load_calibration_data(&nvm_calibration_data);
+ //
+ // adc_enable(&adc_instance_struct);
+ //
+ // uint16_t data;
+ // enum status_code status;
+ //
+ // // Read twice and discard first result, as recommended in section 14 of
+ // // http://www.atmel.com/images/Atmel-42645-ADC-Configurations-with-Examples_ApplicationNote_AT11481.pdf
+ // // "Discard the first conversion result whenever there is a change in ADC configuration
+ // // like voltage reference / ADC channel change"
+ // // Empirical observation shows the first reading is quite different than subsequent ones.
+ //
+ // adc_start_conversion(&adc_instance_struct);
+ // do {
+ // status = adc_read(&adc_instance_struct, &data);
+ // } while (status == STATUS_BUSY);
+ //
+ // adc_start_conversion(&adc_instance_struct);
+ // do {
+ // status = adc_read(&adc_instance_struct, &data);
+ // } while (status == STATUS_BUSY);
+ //
+ // // Disable so that someone else can use the adc with different settings.
+ // adc_disable(&adc_instance_struct);
+ // return calculate_temperature(data, &nvm_calibration_data);
+ return 0;
}
uint32_t common_hal_mcu_processor_get_frequency(void) {
- return system_cpu_clock_get_hz();
+ return 0;
+ //return system_cpu_clock_get_hz();
}
diff --git a/atmel-samd/common-hal/microcontroller/__init__.c b/atmel-samd/common-hal/microcontroller/__init__.c
index 84cea008b..5c119c439 100644
--- a/atmel-samd/common-hal/microcontroller/__init__.c
+++ b/atmel-samd/common-hal/microcontroller/__init__.c
@@ -26,6 +26,7 @@
#include "py/mphal.h"
#include "py/obj.h"
+#include "hal/include/hal_atomic.h"
#include "samd21_pins.h"
@@ -38,17 +39,13 @@ void common_hal_mcu_delay_us(uint32_t delay) {
// Interrupt flags that will be saved and restored during disable/Enable
// interrupt functions below.
-static irqflags_t irq_flags;
+volatile hal_atomic_t flags;
void common_hal_mcu_disable_interrupts(void) {
- // Disable all interrupt sources for timing critical sections.
- // Disable ASF-based interrupts.
- irq_flags = cpu_irq_save();
+ atomic_enter_critical(&flags);
}
void common_hal_mcu_enable_interrupts(void) {
- // Enable all interrupt sources after timing critical sections.
- // Restore ASF-based interrupts.
- cpu_irq_restore(irq_flags);
+ atomic_leave_critical(&flags);
}
// The singleton microcontroller.Processor object, bound to microcontroller.cpu
@@ -62,13 +59,13 @@ mcu_processor_obj_t common_hal_mcu_processor_obj = {
// NVM is only available on Express boards for now.
#if CIRCUITPY_INTERNAL_NVM_SIZE > 0
// The singleton nvm.ByteArray object.
-nvm_bytearray_obj_t common_hal_mcu_nvm_obj = {
- .base = {
- .type = &nvm_bytearray_type,
- },
- .len = NVMCTRL_ROW_SIZE,
- .start_address = (uint8_t*) (FLASH_SIZE - NVMCTRL_ROW_SIZE)
-};
+// nvm_bytearray_obj_t common_hal_mcu_nvm_obj = {
+// .base = {
+// .type = &nvm_bytearray_type,
+// },
+// .len = NVMCTRL_ROW_SIZE,
+// .start_address = (uint8_t*) (FLASH_SIZE - NVMCTRL_ROW_SIZE)
+// };
#endif
// This maps MCU pin names to pin objects.
diff --git a/atmel-samd/common-hal/pulseio/PWMOut.h b/atmel-samd/common-hal/pulseio/PWMOut.h
index 67eabd92e..d6af617a9 100644
--- a/atmel-samd/common-hal/pulseio/PWMOut.h
+++ b/atmel-samd/common-hal/pulseio/PWMOut.h
@@ -28,8 +28,6 @@
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PWMOUT_H
#include "common-hal/microcontroller/Pin.h"
-#include "asf/sam0/drivers/tc/tc.h"
-#include "asf/sam0/drivers/tcc/tcc.h"
#include "py/obj.h"
diff --git a/atmel-samd/common-hal/pulseio/PulseOut.h b/atmel-samd/common-hal/pulseio/PulseOut.h
index 29690fdd1..4294d6d68 100644
--- a/atmel-samd/common-hal/pulseio/PulseOut.h
+++ b/atmel-samd/common-hal/pulseio/PulseOut.h
@@ -28,8 +28,6 @@
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEOUT_H
#include "common-hal/microcontroller/Pin.h"
-#include "asf/sam0/drivers/tc/tc.h"
-#include "asf/sam0/drivers/tcc/tcc.h"
#include "py/obj.h"
diff --git a/atmel-samd/common-hal/usb_hid/types.h b/atmel-samd/common-hal/usb_hid/types.h
index 80e7ef0b5..c276ebd0d 100644
--- a/atmel-samd/common-hal/usb_hid/types.h
+++ b/atmel-samd/common-hal/usb_hid/types.h
@@ -27,8 +27,6 @@
#ifndef MICROPY_INCLUDED_COMMON_HAL_USB_HID_TYPES_H
#define MICROPY_INCLUDED_COMMON_HAL_USB_HID_TYPES_H
-#include "conf_usb.h"
-
#include "py/obj.h"
typedef struct {