Added Unique ID Functions/Updated Support Matrix (#527)
shared_bindings/index.rst: updated Support Matrix format as discussed in PR #503 & Issue #448. shared-bindings/microcontroller/Processor.c & .h: added UID lookup functionality for use with all ports. Fixes #462.
This commit is contained in:
parent
dfa6b6e9c5
commit
44bc1711aa
@ -230,3 +230,20 @@ uint32_t common_hal_mcu_processor_get_frequency(void) {
|
||||
// TODO(tannewt): Determine this dynamically.
|
||||
return CONF_CPU_FREQUENCY;
|
||||
}
|
||||
|
||||
void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {
|
||||
#ifdef SAMD21
|
||||
uint32_t* id_addresses[4] = {(uint32_t *) 0x0080A00C, (uint32_t *) 0x0080A040,
|
||||
(uint32_t *) 0x0080A044, (uint32_t *) 0x0080A048};
|
||||
#endif
|
||||
#ifdef SAMD51
|
||||
uint32_t* id_addresses[4] = {(uint32_t *) 0x008061FC, (uint32_t *) 0x00806010,
|
||||
(uint32_t *) 0x00806014, (uint32_t *) 0x00806018};
|
||||
#endif
|
||||
|
||||
for (int i=0; i<4; i++) {
|
||||
for (int k=0; k<4; k++) {
|
||||
raw_id[4 * i + k] = (*(id_addresses[i]) >> k * 8) & 0xf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,8 @@
|
||||
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H
|
||||
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H
|
||||
|
||||
#define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH 16
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
typedef struct {
|
||||
|
@ -38,3 +38,10 @@ float common_hal_mcu_processor_get_temperature(void) {
|
||||
uint32_t common_hal_mcu_processor_get_frequency(void) {
|
||||
return mp_hal_get_cpu_freq();
|
||||
}
|
||||
|
||||
void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {
|
||||
uint32_t id = system_get_chip_id();
|
||||
for (int i=0; i<4; i++){
|
||||
raw_id[i] = id >> (i * 8);
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,8 @@
|
||||
#ifndef MICROPY_INCLUDED_ESP8266_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H
|
||||
#define MICROPY_INCLUDED_ESP8266_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H
|
||||
|
||||
#define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH 4
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
typedef struct {
|
||||
|
@ -35,3 +35,13 @@ uint32_t common_hal_mcu_processor_get_frequency(void) {
|
||||
return 64000000ul;
|
||||
}
|
||||
|
||||
void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {
|
||||
|
||||
uint32_t* id_addresses[2] = {(uint32_t *) 0x060, (uint32_t *) 0x064};
|
||||
|
||||
for (int i=0; i<2; i++) {
|
||||
for (int k=0; k<4; k++) {
|
||||
raw_id[4 * i + k] = (*(id_addresses[i]) >> k * 8) & 0xf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,8 @@
|
||||
#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H
|
||||
#define MICROPY_INCLUDED_NRF_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H
|
||||
|
||||
#define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH 8
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
typedef struct {
|
||||
|
@ -11,34 +11,39 @@ limited. For example, a microcontroller without analog features will not have
|
||||
|
||||
Support Matrix
|
||||
---------------
|
||||
NOTE 1: **All Supported** means the following ports are supported: SAMD21, SAMD21 Express,
|
||||
SAMD51, SAMD51 Express, and ESP8266.
|
||||
|
||||
================= ======= ============== =======
|
||||
Module / Port SAMD21 SAMD21 Express ESP8266
|
||||
================= ======= ============== =======
|
||||
`analogio` **Yes** **Yes** **Yes**
|
||||
`audiobusio` **Yes** **Yes** No
|
||||
`audioio` No **Yes** No
|
||||
`bitbangio` No **Yes** **Yes**
|
||||
`board` **Yes** **Yes** **Yes**
|
||||
`busio` **Yes** **Yes** **Yes**
|
||||
`digitalio` **Yes** **Yes** **Yes**
|
||||
`gamepad` No **Yes** No
|
||||
`math` **Yes** **Yes** **Yes**
|
||||
`microcontroller` **Yes** **Yes** **Yes**
|
||||
`multiterminal` No No **Yes**
|
||||
`neopixel_write` **Yes** **Yes** **Yes**
|
||||
`nvm` No **Yes** No
|
||||
`os` **Yes** **Yes** **Yes**
|
||||
`pulseio` **Yes** **Yes** No
|
||||
`random` **Yes** **Yes** **Yes**
|
||||
`storage` **Yes** **Yes** **Yes**
|
||||
`struct` **Yes** **Yes** **Yes**
|
||||
`supervisor` **Yes** **Yes** No
|
||||
`time` **Yes** **Yes** **Yes**
|
||||
`touchio` **Yes** **Yes** No
|
||||
`uheap` Debug Debug Debug
|
||||
`usb_hid` **Yes** **Yes** No
|
||||
================= ======= ============== =======
|
||||
NOTE 2: **SAMD** and/or **SAMD Express** without additional numbers, means both SAMD21 & SAMD51 versions
|
||||
are supported.
|
||||
|
||||
================= ===============
|
||||
Module Supported Ports
|
||||
================= ===============
|
||||
`analogio` **All Supported**
|
||||
`audiobusio` **SAMD/SAMD Express**
|
||||
`audioio` **SAMD Express**
|
||||
`bitbangio` **SAMD Express, ESP8266**
|
||||
`board` **All Supported**
|
||||
`busio` **All Supported**
|
||||
`digitalio` **All Supported**
|
||||
`gamepad` **SAMD Express**
|
||||
`math` **All Supported**
|
||||
`microcontroller` **All Supported**
|
||||
`multiterminal` **ESP8266**
|
||||
`neopixel_write` **All Supported**
|
||||
`nvm` **SAMD Express**
|
||||
`os` **All Supported**
|
||||
`pulseio` **SAMD/SAMD Express**
|
||||
`random` **All Supported**
|
||||
`storage` **All Supported**
|
||||
`struct` **All Supported**
|
||||
`supervisor` **SAMD/SAMD Express**
|
||||
`time` **All Supported**
|
||||
`touchio` **SAMD/SAMD Express**
|
||||
`uheap` **Debug (All)**
|
||||
`usb_hid` **SAMD/SAMD Express**
|
||||
================= ===============
|
||||
|
||||
Modules
|
||||
---------
|
||||
|
@ -32,7 +32,6 @@
|
||||
|
||||
#include "py/objproperty.h"
|
||||
|
||||
#include "py/objproperty.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
//| .. currentmodule:: microcontroller
|
||||
@ -93,9 +92,31 @@ const mp_obj_property_t mcu_processor_temperature_obj = {
|
||||
},
|
||||
};
|
||||
|
||||
//| .. attribute:: uid
|
||||
//|
|
||||
//| Return the unique id (aka serial number) of the chip.
|
||||
//| Returns a bytearray object.
|
||||
//|
|
||||
STATIC mp_obj_t mcu_processor_get_uid(mp_obj_t self) {
|
||||
uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH];
|
||||
common_hal_mcu_processor_get_uid(raw_id);
|
||||
return mp_obj_new_bytearray(sizeof(raw_id), raw_id);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(mcu_processor_get_uid_obj, mcu_processor_get_uid);
|
||||
|
||||
const mp_obj_property_t mcu_processor_uid_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&mcu_processor_get_uid_obj, // getter
|
||||
(mp_obj_t)&mp_const_none_obj, // no setter
|
||||
(mp_obj_t)&mp_const_none_obj, // no deleter
|
||||
},
|
||||
};
|
||||
|
||||
STATIC const mp_rom_map_elem_t mcu_processor_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_frequency), MP_ROM_PTR(&mcu_processor_frequency_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_temperature), MP_ROM_PTR(&mcu_processor_temperature_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_uid), MP_ROM_PTR(&mcu_processor_uid_obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(mcu_processor_locals_dict, mcu_processor_locals_dict_table);
|
||||
|
@ -35,5 +35,6 @@ const mp_obj_type_t mcu_processor_type;
|
||||
|
||||
uint32_t common_hal_mcu_processor_get_frequency(void);
|
||||
float common_hal_mcu_processor_get_temperature(void);
|
||||
void common_hal_mcu_processor_get_uid(uint8_t raw_id[]);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_MICROCONTROLLER_PROCESSOR_H
|
||||
|
Loading…
Reference in New Issue
Block a user