Skip to content
Snippets Groups Projects
Select Git revision
  • 8e3af7d4c80bfd9047431eb62804ecd4f60cdb9f
  • master default protected
  • wip-bootstrap
3 results

modmachine.c

Blame
  • Forked from card10 / micropython
    Source project has a limited visibility.
    modmachine.c 10.45 KiB
    /*
     * This file is part of the MicroPython project, http://micropython.org/
     *
     * Development of the code in this file was sponsored by Microbric Pty Ltd
     *
     * The MIT License (MIT)
     *
     * Copyright (c) 2013-2015 Damien P. George
     * Copyright (c) 2016 Paul Sokolovsky
     *
     * 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 <stdint.h>
    #include <stdio.h>
    
    #include "freertos/FreeRTOS.h"
    #include "freertos/task.h"
    #include "rom/ets_sys.h"
    #include "rom/rtc.h"
    #include "esp_clk.h"
    #include "esp_pm.h"
    #include "driver/touch_pad.h"
    
    #include "py/obj.h"
    #include "py/runtime.h"
    #include "extmod/machine_mem.h"
    #include "extmod/machine_signal.h"
    #include "extmod/machine_pulse.h"
    #include "extmod/machine_i2c.h"
    #include "extmod/machine_spi.h"
    #include "modmachine.h"
    #include "machine_rtc.h"
    
    #if MICROPY_PY_MACHINE
    
    typedef enum {
        MP_PWRON_RESET = 1,
        MP_HARD_RESET,
        MP_WDT_RESET,
        MP_DEEPSLEEP_RESET,
        MP_SOFT_RESET
    } reset_reason_t;
    
    STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
        if (n_args == 0) {
            // get
            return mp_obj_new_int(esp_clk_cpu_freq());
        } else {
            // set
            mp_int_t freq = mp_obj_get_int(args[0]) / 1000000;
            if (freq != 20 && freq != 40 && freq != 80 && freq != 160 && freq != 240) {
                mp_raise_ValueError("frequency must be 20MHz, 40MHz, 80Mhz, 160MHz or 240MHz");
            }