pybpin.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. * Copyright (c) 2015 Daniel Campora
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. */
  27. #ifndef MICROPY_INCLUDED_CC3200_MODS_PYBPIN_H
  28. #define MICROPY_INCLUDED_CC3200_MODS_PYBPIN_H
  29. enum {
  30. PORT_A0 = GPIOA0_BASE,
  31. PORT_A1 = GPIOA1_BASE,
  32. PORT_A2 = GPIOA2_BASE,
  33. PORT_A3 = GPIOA3_BASE,
  34. };
  35. enum {
  36. PIN_FN_UART = 0,
  37. PIN_FN_SPI,
  38. PIN_FN_I2S,
  39. PIN_FN_I2C,
  40. PIN_FN_TIM,
  41. PIN_FN_SD,
  42. PIN_FN_ADC,
  43. };
  44. enum {
  45. PIN_TYPE_UART_TX = 0,
  46. PIN_TYPE_UART_RX,
  47. PIN_TYPE_UART_RTS,
  48. PIN_TYPE_UART_CTS,
  49. };
  50. enum {
  51. PIN_TYPE_SPI_CLK = 0,
  52. PIN_TYPE_SPI_MOSI,
  53. PIN_TYPE_SPI_MISO,
  54. PIN_TYPE_SPI_CS0,
  55. };
  56. enum {
  57. PIN_TYPE_I2S_CLK = 0,
  58. PIN_TYPE_I2S_FS,
  59. PIN_TYPE_I2S_DAT0,
  60. PIN_TYPE_I2S_DAT1,
  61. };
  62. enum {
  63. PIN_TYPE_I2C_SDA = 0,
  64. PIN_TYPE_I2C_SCL,
  65. };
  66. enum {
  67. PIN_TYPE_TIM_PWM = 0,
  68. };
  69. enum {
  70. PIN_TYPE_SD_CLK = 0,
  71. PIN_TYPE_SD_CMD,
  72. PIN_TYPE_SD_DAT0,
  73. };
  74. enum {
  75. PIN_TYPE_ADC_CH0 = 0,
  76. PIN_TYPE_ADC_CH1,
  77. PIN_TYPE_ADC_CH2,
  78. PIN_TYPE_ADC_CH3,
  79. };
  80. typedef struct {
  81. qstr name;
  82. int8_t idx;
  83. uint8_t fn;
  84. uint8_t unit;
  85. uint8_t type;
  86. } pin_af_t;
  87. typedef struct {
  88. const mp_obj_base_t base;
  89. const qstr name;
  90. const uint32_t port;
  91. const pin_af_t *af_list;
  92. uint16_t pull;
  93. const uint8_t bit;
  94. const uint8_t pin_num;
  95. int8_t af;
  96. uint8_t strength;
  97. uint8_t mode; // this is now a combination of type and mode
  98. const uint8_t num_afs; // 255 AFs
  99. uint8_t value;
  100. uint8_t used;
  101. uint8_t irq_trigger;
  102. uint8_t irq_flags;
  103. } pin_obj_t;
  104. extern const mp_obj_type_t pin_type;
  105. typedef struct {
  106. const char *name;
  107. const pin_obj_t *pin;
  108. } pin_named_pin_t;
  109. typedef struct {
  110. mp_obj_base_t base;
  111. qstr name;
  112. const pin_named_pin_t *named_pins;
  113. } pin_named_pins_obj_t;
  114. extern const mp_obj_type_t pin_board_pins_obj_type;
  115. extern const mp_obj_dict_t pin_board_pins_locals_dict;
  116. void pin_init0(void);
  117. void pin_config(pin_obj_t *self, int af, uint mode, uint type, int value, uint strength);
  118. pin_obj_t *pin_find(mp_obj_t user_obj);
  119. void pin_assign_pins_af (mp_obj_t *pins, uint32_t n_pins, uint32_t pull, uint32_t fn, uint32_t unit);
  120. uint8_t pin_find_peripheral_unit (const mp_obj_t pin, uint8_t fn, uint8_t type);
  121. uint8_t pin_find_peripheral_type (const mp_obj_t pin, uint8_t fn, uint8_t unit);
  122. int8_t pin_find_af_index (const pin_obj_t* pin, uint8_t fn, uint8_t unit, uint8_t type);;
  123. #endif // MICROPY_INCLUDED_CC3200_MODS_PYBPIN_H