pin.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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_STM32_PIN_H
  27. #define MICROPY_INCLUDED_STM32_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. void *reg; // The peripheral associated with this AF
  40. } pin_af_obj_t;
  41. typedef struct {
  42. mp_obj_base_t base;
  43. qstr name;
  44. uint32_t port : 4;
  45. uint32_t pin : 5; // Some ARM processors use 32 bits/PORT
  46. uint32_t num_af : 4;
  47. uint32_t adc_channel : 5; // Some ARM processors use 32 bits/PORT
  48. uint32_t adc_num : 3; // 1 bit per ADC
  49. uint32_t pin_mask;
  50. pin_gpio_t *gpio;
  51. const pin_af_obj_t *af;
  52. } pin_obj_t;
  53. extern const mp_obj_type_t pin_type;
  54. extern const mp_obj_type_t pin_af_type;
  55. // Include all of the individual pin objects
  56. #include "genhdr/pins.h"
  57. typedef struct {
  58. const char *name;
  59. const pin_obj_t *pin;
  60. } pin_named_pin_t;
  61. extern const pin_named_pin_t pin_board_pins[];
  62. extern const pin_named_pin_t pin_cpu_pins[];
  63. //extern pin_map_obj_t pin_map_obj;
  64. typedef struct {
  65. mp_obj_base_t base;
  66. qstr name;
  67. const pin_named_pin_t *named_pins;
  68. } pin_named_pins_obj_t;
  69. extern const mp_obj_type_t pin_board_pins_obj_type;
  70. extern const mp_obj_type_t pin_cpu_pins_obj_type;
  71. extern const mp_obj_dict_t pin_cpu_pins_locals_dict;
  72. extern const mp_obj_dict_t pin_board_pins_locals_dict;
  73. MP_DECLARE_CONST_FUN_OBJ_KW(pin_init_obj);
  74. void pin_init0(void);
  75. uint32_t pin_get_mode(const pin_obj_t *pin);
  76. uint32_t pin_get_pull(const pin_obj_t *pin);
  77. uint32_t pin_get_af(const pin_obj_t *pin);
  78. const pin_obj_t *pin_find(mp_obj_t user_obj);
  79. const pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name);
  80. const pin_af_obj_t *pin_find_af(const pin_obj_t *pin, uint8_t fn, uint8_t unit);
  81. const pin_af_obj_t *pin_find_af_by_index(const pin_obj_t *pin, mp_uint_t af_idx);
  82. const pin_af_obj_t *pin_find_af_by_name(const pin_obj_t *pin, const char *name);
  83. #endif // MICROPY_INCLUDED_STM32_PIN_H