pin.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2013, 2014 Damien P. George
  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 __MICROPY_INCLUDED_NRF5_PIN_H__
  27. #define __MICROPY_INCLUDED_NRF5_PIN_H__
  28. // This file requires pin_defs_xxx.h (which has port specific enums and
  29. // defines, so we include it here. It should never be included directly
  30. #include MICROPY_PIN_DEFS_PORT_H
  31. #include "py/obj.h"
  32. typedef struct {
  33. mp_obj_base_t base;
  34. qstr name;
  35. uint8_t idx;
  36. uint8_t fn;
  37. uint8_t unit;
  38. uint8_t type;
  39. union {
  40. void *reg;
  41. PIN_DEFS_PORT_AF_UNION
  42. };
  43. } pin_af_obj_t;
  44. typedef struct {
  45. mp_obj_base_t base;
  46. qstr name;
  47. uint32_t pin : 8;
  48. uint32_t num_af : 4;
  49. uint32_t adc_channel : 5; // Some ARM processors use 32 bits/PORT
  50. uint32_t adc_num : 3; // 1 bit per ADC
  51. const pin_af_obj_t *af;
  52. uint32_t pull;
  53. } pin_obj_t;
  54. extern const mp_obj_type_t pin_type;
  55. extern const mp_obj_type_t pin_af_type;
  56. typedef struct {
  57. const char *name;
  58. const pin_obj_t *pin;
  59. } pin_named_pin_t;
  60. extern const pin_named_pin_t pin_board_pins[];
  61. extern const pin_named_pin_t pin_cpu_pins[];
  62. //extern pin_map_obj_t pin_map_obj;
  63. typedef struct {
  64. mp_obj_base_t base;
  65. qstr name;
  66. const pin_named_pin_t *named_pins;
  67. } pin_named_pins_obj_t;
  68. extern const mp_obj_type_t pin_board_pins_obj_type;
  69. extern const mp_obj_type_t pin_cpu_pins_obj_type;
  70. extern const mp_obj_dict_t pin_cpu_pins_locals_dict;
  71. extern const mp_obj_dict_t pin_board_pins_locals_dict;
  72. MP_DECLARE_CONST_FUN_OBJ_KW(pin_init_obj);
  73. void pin_init0(void);
  74. uint32_t pin_get_mode(const pin_obj_t *pin);
  75. uint32_t pin_get_pull(const pin_obj_t *pin);
  76. uint32_t pin_get_af(const pin_obj_t *pin);
  77. const pin_obj_t *pin_find(mp_obj_t user_obj);
  78. const pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name);
  79. const pin_af_obj_t *pin_find_af(const pin_obj_t *pin, uint8_t fn, uint8_t unit);
  80. const pin_af_obj_t *pin_find_af_by_index(const pin_obj_t *pin, mp_uint_t af_idx);
  81. const pin_af_obj_t *pin_find_af_by_name(const pin_obj_t *pin, const char *name);
  82. #endif // __MICROPY_INCLUDED_NRF5_PIN_H__