Merge pull request #1 from ajbaabf/nrf5_no_sdk
added support for hardware temperature sensor
This commit is contained in:
commit
c1ffac9998
|
@ -119,6 +119,7 @@ SRC_HAL = $(addprefix hal/,\
|
|||
hal_twi.c \
|
||||
hal_adc.c \
|
||||
hal_adce.c \
|
||||
hal_temp.c \
|
||||
)
|
||||
|
||||
ifeq ($(MCU_VARIANT), nrf52)
|
||||
|
@ -161,6 +162,7 @@ DRIVERS_SRC_C += $(addprefix modules/,\
|
|||
machine/rtc.c \
|
||||
machine/pwm.c \
|
||||
machine/led.c \
|
||||
machine/temp.c \
|
||||
usocket/modusocket.c \
|
||||
network/modnetwork.c \
|
||||
uos/moduos.c \
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#define MICROPY_PY_MACHINE_HW_SPI (0)
|
||||
#define MICROPY_PY_MACHINE_PWM (0)
|
||||
#define MICROPY_PY_MACHINE_TEMP (1)
|
||||
|
||||
#define MICROPY_HW_HAS_SWITCH (0)
|
||||
#define MICROPY_HW_HAS_FLASH (0)
|
||||
|
|
|
@ -3,5 +3,6 @@
|
|||
|
||||
#define HAL_UART_MODULE_ENABLED
|
||||
#define HAL_TIME_MODULE_ENABLED
|
||||
#define HAL_TEMP_MODULE_ENABLED
|
||||
|
||||
#endif // NRF51_HAL_CONF_H__
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#define MICROPY_PY_MACHINE_HW_SPI (0)
|
||||
#define MICROPY_PY_MACHINE_PWM (0)
|
||||
#define MICROPY_PY_MACHINE_TEMP (1)
|
||||
|
||||
#define MICROPY_HW_HAS_SWITCH (0)
|
||||
#define MICROPY_HW_HAS_FLASH (0)
|
||||
|
@ -46,6 +47,7 @@
|
|||
#define MICROPY_HW_ENABLE_DAC (0)
|
||||
#define MICROPY_HW_ENABLE_CAN (0)
|
||||
|
||||
|
||||
#define MICROPY_HW_LED_COUNT (2)
|
||||
#define MICROPY_HW_LED_PULLUP (0)
|
||||
|
||||
|
@ -57,6 +59,6 @@
|
|||
#define MICROPY_HW_UART1_TX (pin_A9)
|
||||
#define MICROPY_HW_UART1_CTS (pin_A10)
|
||||
#define MICROPY_HW_UART1_RTS (pin_A8)
|
||||
#define MICROPY_HW_UART1_HWFC (1)
|
||||
#define MICROPY_HW_UART1_HWFC (0)
|
||||
|
||||
#define HELP_TEXT_BOARD_LED "1,2"
|
||||
|
|
|
@ -4,5 +4,10 @@
|
|||
#define HAL_UART_MODULE_ENABLED
|
||||
// #define HAL_SPI_MODULE_ENABLED
|
||||
#define HAL_TIME_MODULE_ENABLED
|
||||
#define HAL_RTC_MODULE_ENABLED
|
||||
#define HAL_TIMER_MODULE_ENABLED
|
||||
#define HAL_TWI_MODULE_ENABLED
|
||||
#define HAL_ADC_MODULE_ENABLED
|
||||
#define HAL_TEMP_MODULE_ENABLED
|
||||
|
||||
#endif // NRF51_HAL_CONF_H__
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#define MICROPY_PY_MACHINE_RTC (1)
|
||||
#define MICROPY_PY_MACHINE_I2C (1)
|
||||
#define MICROPY_PY_MACHINE_ADC (1)
|
||||
#define MICROPY_PY_MACHINE_TEMP (1)
|
||||
|
||||
#define MICROPY_PY_USOCKET (0)
|
||||
#define MICROPY_PY_NETWORK (0)
|
||||
|
|
|
@ -8,5 +8,6 @@
|
|||
#define HAL_TIMER_MODULE_ENABLED
|
||||
#define HAL_TWI_MODULE_ENABLED
|
||||
#define HAL_ADC_MODULE_ENABLED
|
||||
#define HAL_TEMP_MODULE_ENABLED
|
||||
|
||||
#endif // NRF51_HAL_CONF_H__
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#define MICROPY_PY_SYS_PLATFORM "nrf51-dongle"
|
||||
|
||||
#define MICROPY_PY_MACHINE_PWM (0)
|
||||
#define MICROPY_PY_MACHINE_TEMP (1)
|
||||
|
||||
#define MICROPY_HW_HAS_SWITCH (0)
|
||||
#define MICROPY_HW_HAS_FLASH (0)
|
||||
|
|
|
@ -4,5 +4,6 @@
|
|||
#define HAL_UART_MODULE_ENABLED
|
||||
#define HAL_SPI_MODULE_ENABLED
|
||||
#define HAL_TIME_MODULE_ENABLED
|
||||
#define HAL_TEMP_MODULE_ENABLED
|
||||
|
||||
#endif // NRF51_HAL_CONF_H__
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#define MICROPY_PY_MACHINE_RTC (1)
|
||||
#define MICROPY_PY_MACHINE_I2C (1)
|
||||
#define MICROPY_PY_MACHINE_ADC (1)
|
||||
#define MICROPY_PY_MACHINE_TEMP (1)
|
||||
|
||||
#define MICROPY_PY_DISPLAY (1)
|
||||
#define MICROPY_PY_DISPLAY_EPAPER_SLD00200P (1)
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#define HAL_TIMER_MODULE_ENABLED
|
||||
#define HAL_TWI_MODULE_ENABLED
|
||||
#define HAL_ADCE_MODULE_ENABLED
|
||||
#define HAL_TEMP_MODULE_ENABLED
|
||||
// #define HAL_UARTE_MODULE_ENABLED
|
||||
// #define HAL_SPIE_MODULE_ENABLED
|
||||
// #define HAL_TWIE_MODULE_ENABLED
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#define MICROPY_PY_MACHINE_HW_SPI (1)
|
||||
#define MICROPY_PY_MACHINE_I2C (1)
|
||||
#define MICROPY_PY_MACHINE_ADC (1)
|
||||
#define MICROPY_PY_MACHINE_TEMP (1)
|
||||
|
||||
#define MICROPY_PY_DISPLAY (1)
|
||||
#define MICROPY_PY_DISPLAY_EPAPER_SLD00200P (1)
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#define HAL_TIMER_MODULE_ENABLED
|
||||
#define HAL_TWI_MODULE_ENABLED
|
||||
#define HAL_ADCE_MODULE_ENABLED
|
||||
#define HAL_TEMP_MODULE_ENABLED
|
||||
// #define HAL_UARTE_MODULE_ENABLED
|
||||
// #define HAL_SPIE_MODULE_ENABLED
|
||||
// #define HAL_TWIE_MODULE_ENABLED
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Bander F. Ajba
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "mphalport.h"
|
||||
#include "hal_temp.h"
|
||||
|
||||
#ifdef HAL_TEMP_MODULE_ENABLED
|
||||
|
||||
void hal_temp_init(void) {
|
||||
// @note Workaround for PAN_028 rev2.0A anomaly 31 - TEMP: Temperature offset value has to be manually loaded to the TEMP module
|
||||
*(uint32_t *) 0x4000C504 = 0;
|
||||
}
|
||||
|
||||
int32_t hal_temp_read(void) {
|
||||
int32_t volatile temp;
|
||||
hal_temp_init();
|
||||
|
||||
NRF_TEMP->TASKS_START = 1; // Start the temperature measurement.
|
||||
|
||||
while (NRF_TEMP->EVENTS_DATARDY == 0) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
NRF_TEMP->EVENTS_DATARDY = 0;
|
||||
|
||||
// @note Workaround for PAN_028 rev2.0A anomaly 29 - TEMP: Stop task clears the TEMP register.
|
||||
temp = (((NRF_TEMP->TEMP & MASK_SIGN) != 0) ? (NRF_TEMP->TEMP | MASK_SIGN_EXTENSION) : (NRF_TEMP->TEMP) / 4);
|
||||
|
||||
// @note Workaround for PAN_028 rev2.0A anomaly 30 - TEMP: Temp module analog front end does not power down when DATARDY event occurs.
|
||||
NRF_TEMP->TASKS_STOP = 1; // Stop the temperature measurement.
|
||||
return temp;
|
||||
}
|
||||
|
||||
#endif // HAL_TEMP_MODULE_ENABLED
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Bander F. Ajba
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef HAL_TEMP_H__
|
||||
#define HAL_TEMP_H__
|
||||
|
||||
#include "nrf.h"
|
||||
|
||||
#define MASK_SIGN (0x00000200UL)
|
||||
#define MASK_SIGN_EXTENSION (0xFFFFFC00UL)
|
||||
|
||||
void hal_temp_init(void);
|
||||
|
||||
int32_t hal_temp_read(void);
|
||||
|
||||
#endif
|
|
@ -46,6 +46,9 @@
|
|||
#if MICROPY_PY_MACHINE_ADC
|
||||
#include "adc.h"
|
||||
#endif
|
||||
#if MICROPY_PY_MACHINE_TEMP
|
||||
#include "temp.h"
|
||||
#endif
|
||||
|
||||
|
||||
#define PYB_RESET_HARD (0)
|
||||
|
@ -180,6 +183,9 @@ STATIC const mp_map_elem_t machine_module_globals_table[] = {
|
|||
#endif
|
||||
#if MICROPY_PY_MACHINE_PWM
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_PWM), (mp_obj_t)&machine_hard_pwm_type },
|
||||
#endif
|
||||
#if MICROPY_PY_MACHINE_TEMP
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_Temp), (mp_obj_t)&machine_temp_type },
|
||||
#endif
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_HARD_RESET), MP_OBJ_NEW_SMALL_INT(PYB_RESET_HARD) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_WDT_RESET), MP_OBJ_NEW_SMALL_INT(PYB_RESET_WDT) },
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Bander F. Ajba
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/mphal.h"
|
||||
#include "temp.h"
|
||||
#include "hal_temp.h"
|
||||
|
||||
#if MICROPY_PY_MACHINE_TEMP
|
||||
|
||||
typedef struct _machine_temp_obj_t {
|
||||
mp_obj_base_t base;
|
||||
} machine_temp_obj_t;
|
||||
|
||||
/// \method __str__()
|
||||
/// Return a string describing the Temp object.
|
||||
STATIC void machine_temp_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
|
||||
machine_temp_obj_t *self = o;
|
||||
|
||||
(void)self;
|
||||
|
||||
mp_printf(print, "Temp");
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* MicroPython bindings for machine API */
|
||||
|
||||
STATIC mp_obj_t machine_temp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ },
|
||||
};
|
||||
|
||||
// parse args
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
machine_temp_obj_t *self = m_new_obj(machine_temp_obj_t);
|
||||
|
||||
self->base.type = &machine_temp_type;
|
||||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
/// \method read()
|
||||
/// Get temperature.
|
||||
STATIC mp_obj_t machine_temp_read(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
|
||||
return MP_OBJ_NEW_SMALL_INT(hal_temp_read());
|
||||
}
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_machine_temp_read_obj, 0, 1, machine_temp_read);
|
||||
|
||||
STATIC const mp_map_elem_t machine_temp_locals_dict_table[] = {
|
||||
// instance methods
|
||||
// class methods
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_read), (mp_obj_t)&mp_machine_temp_read_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(machine_temp_locals_dict, machine_temp_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t machine_temp_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_Temp,
|
||||
.make_new = machine_temp_make_new,
|
||||
.locals_dict = (mp_obj_t)&machine_temp_locals_dict,
|
||||
.print = machine_temp_print,
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_MACHINE_TEMP
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* This file is part of the Micro Python project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Bander F. Ajba
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef TEMP_H__
|
||||
#define TEMP_H__
|
||||
|
||||
extern const mp_obj_type_t machine_temp_type;
|
||||
|
||||
int32_t temp_read(void);
|
||||
|
||||
#endif // TEMP_H__
|
Loading…
Reference in New Issue