mphalport.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2015 Glenn Ruben Bakke
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #ifndef __NRF52_HAL
  27. #define __NRF52_HAL
  28. #include "py/mpconfig.h"
  29. #include <nrfx.h>
  30. #include "pin.h"
  31. #include "nrf_gpio.h"
  32. #include "nrfx_config.h"
  33. typedef enum
  34. {
  35. HAL_OK = 0x00,
  36. HAL_ERROR = 0x01,
  37. HAL_BUSY = 0x02,
  38. HAL_TIMEOUT = 0x03
  39. } HAL_StatusTypeDef;
  40. static inline uint32_t hal_tick_fake(void) {
  41. return 0;
  42. }
  43. #define mp_hal_ticks_ms hal_tick_fake // TODO: implement. Right now, return 0 always
  44. extern const unsigned char mp_hal_status_to_errno_table[4];
  45. NORETURN void mp_hal_raise(HAL_StatusTypeDef status);
  46. void mp_hal_set_interrupt_char(int c); // -1 to disable
  47. int mp_hal_stdin_rx_chr(void);
  48. void mp_hal_stdout_tx_str(const char *str);
  49. void mp_hal_delay_ms(mp_uint_t ms);
  50. void mp_hal_delay_us(mp_uint_t us);
  51. const char * nrfx_error_code_lookup(uint32_t err_code);
  52. #define mp_hal_pin_obj_t const pin_obj_t*
  53. #define mp_hal_get_pin_obj(o) pin_find(o)
  54. #define mp_hal_pin_high(p) nrf_gpio_pin_set(p->pin)
  55. #define mp_hal_pin_low(p) nrf_gpio_pin_clear(p->pin)
  56. #define mp_hal_pin_read(p) (nrf_gpio_pin_dir_get(p->pin) == NRF_GPIO_PIN_DIR_OUTPUT) ? nrf_gpio_pin_out_read(p->pin) : nrf_gpio_pin_read(p->pin)
  57. #define mp_hal_pin_write(p, v) do { if (v) { mp_hal_pin_high(p); } else { mp_hal_pin_low(p); } } while (0)
  58. #define mp_hal_pin_od_low(p) mp_hal_pin_low(p)
  59. #define mp_hal_pin_od_high(p) mp_hal_pin_high(p)
  60. #define mp_hal_pin_open_drain(p) nrf_gpio_cfg_input(p->pin, NRF_GPIO_PIN_NOPULL)
  61. // TODO: empty implementation for now. Used by machine_spi.c:69
  62. #define mp_hal_delay_us_fast(p)
  63. #define mp_hal_ticks_us() (0)
  64. #define mp_hal_ticks_cpu() (0)
  65. #endif