Browse Source

esp8266: Add uos module

Currently implements only .uname()
pull/1291/head
Josef Gajdusek 10 years ago
committed by Paul Sokolovsky
parent
commit
59610c4004
  1. 1
      esp8266/Makefile
  2. 79
      esp8266/moduos.c
  3. 4
      esp8266/mpconfigport.h
  4. 10
      esp8266/qstrdefsport.h

1
esp8266/Makefile

@ -59,6 +59,7 @@ SRC_C = \
modpybrtc.c \ modpybrtc.c \
modesp.c \ modesp.c \
modutime.c \ modutime.c \
moduos.c \
utils.c \ utils.c \
$(BUILD)/frozen.c \ $(BUILD)/frozen.c \

79
esp8266/moduos.c

@ -0,0 +1,79 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2015 Josef Gajdusek
*
* 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 <string.h>
#include "py/mpconfig.h"
#include "py/nlr.h"
#include "py/obj.h"
#include "py/objtuple.h"
#include "py/objstr.h"
#include "genhdr/mpversion.h"
#include "user_interface.h"
STATIC const qstr os_uname_info_fields[] = {
MP_QSTR_sysname, MP_QSTR_nodename,
MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine
};
STATIC const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_PY_SYS_PLATFORM);
STATIC const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_PY_SYS_PLATFORM);
STATIC const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE);
STATIC const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME);
STATIC mp_obj_tuple_t os_uname_info_obj = {
.base = {&mp_type_attrtuple},
.len = 5,
.items = {
(mp_obj_t)&os_uname_info_sysname_obj,
(mp_obj_t)&os_uname_info_nodename_obj,
NULL,
(mp_obj_t)&os_uname_info_version_obj,
(mp_obj_t)&os_uname_info_machine_obj,
(void *)os_uname_info_fields,
}
};
STATIC mp_obj_t os_uname(void) {
if (os_uname_info_obj.items[2] == NULL) {
const char *ver = system_get_sdk_version();
os_uname_info_obj.items[2] = mp_obj_new_str(ver, strlen(ver), false);
}
return (mp_obj_t)&os_uname_info_obj;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname);
STATIC const mp_map_elem_t os_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_uos) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_uname), (mp_obj_t)&os_uname_obj },
};
STATIC MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table);
const mp_obj_module_t uos_module = {
.base = { &mp_type_module },
.name = MP_QSTR_uos,
.globals = (mp_obj_dict_t*)&os_module_globals,
};

4
esp8266/mpconfigport.h

@ -66,14 +66,17 @@ extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj;
extern const struct _mp_obj_module_t pyb_module; extern const struct _mp_obj_module_t pyb_module;
extern const struct _mp_obj_module_t esp_module; extern const struct _mp_obj_module_t esp_module;
extern const struct _mp_obj_module_t utime_module; extern const struct _mp_obj_module_t utime_module;
extern const struct _mp_obj_module_t uos_module;
#define MICROPY_PORT_BUILTIN_MODULES \ #define MICROPY_PORT_BUILTIN_MODULES \
{ MP_OBJ_NEW_QSTR(MP_QSTR_pyb), (mp_obj_t)&pyb_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_pyb), (mp_obj_t)&pyb_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_esp), (mp_obj_t)&esp_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_esp), (mp_obj_t)&esp_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_utime), (mp_obj_t)&utime_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_utime), (mp_obj_t)&utime_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&uos_module }, \
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \ #define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&utime_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&utime_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&uos_module }, \
#define MP_STATE_PORT MP_STATE_VM #define MP_STATE_PORT MP_STATE_VM
@ -92,3 +95,4 @@ extern const struct _mp_obj_module_t utime_module;
#define MICROPY_HAL_H "esp_mphal.h" #define MICROPY_HAL_H "esp_mphal.h"
#define MICROPY_HW_BOARD_NAME "ESP module" #define MICROPY_HW_BOARD_NAME "ESP module"
#define MICROPY_HW_MCU_NAME "ESP8266" #define MICROPY_HW_MCU_NAME "ESP8266"
#define MICROPY_PY_SYS_PLATFORM "ESP8266"

10
esp8266/qstrdefsport.h

@ -41,6 +41,16 @@ Q(udelay)
Q(sync) Q(sync)
Q(hard_reset) Q(hard_reset)
// uos module
Q(uos)
Q(os)
Q(uname)
Q(sysname)
Q(nodename)
Q(release)
Q(version)
Q(machine)
Q(esp) Q(esp)
Q(socket) Q(socket)
Q(connect) Q(connect)

Loading…
Cancel
Save