123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- #include "hw_io_pin.h"
- #include "board.h"
- typedef struct
- {
- unsigned long gpio; //蝞∟����沌ORT
- unsigned short pin; //蝞∟����沌IN
- unsigned short level; //蝞∟��㗇��萄像 �芾��?�𤥁�?
- unsigned long pupd; //銝𠹺��西挽蝵?
- } io_pin_t;
- static const io_pin_t io_input_map[IO_PIN_INPUT_NUMBER] = {
- { GPIOB, 9, 0, GPIO_PUPD_PULLUP }, //0
- { GPIOB, 7, 0, GPIO_PUPD_PULLUP }, //1
- { GPIOB, 6, 0, GPIO_PUPD_PULLUP }, //2
- { GPIOB, 5, 0, GPIO_PUPD_PULLUP }, //3
- { GPIOB, 4, 0, GPIO_PUPD_PULLUP }, //4
- { GPIOB, 3, 0, GPIO_PUPD_PULLUP }, //5
- { GPIOA, 15, 0, GPIO_PUPD_PULLUP }, //6
- { GPIOA, 12, 0, GPIO_PUPD_PULLUP } //7
- };
- static const io_pin_t io_output_map[IO_PIN_OUTPUT_NUMBER] = {
- { GPIOA, 4, 0, GPIO_PUPD_NONE }, //0
- { GPIOA, 5, 0, GPIO_PUPD_NONE }, //1
- { GPIOA, 6, 0, GPIO_PUPD_NONE }, //2
- { GPIOA, 7, 0, GPIO_PUPD_NONE }, //3
- { GPIOB, 0, 0, GPIO_PUPD_NONE }, //4
- { GPIOB, 1, 0, GPIO_PUPD_NONE } //5
- };
- #define OUTPUT_ENABLE_PORT GPIOB
- #define OUTPUT_ENABLE_PIN 12
- #define OUTPUT_ENABLE() GPIO_BOP(OUTPUT_ENABLE_PORT) = 1 << (OUTPUT_ENABLE_PIN)
- #define OUTPUT_DISABLE() GPIO_BOP(OUTPUT_ENABLE_PORT) = 1 << (OUTPUT_ENABLE_PIN + 16)
- #define OUTPUT_LED_PORT GPIOA
- #define OUTPUT_LED_PIN 15
- #define OUTPUT_LED_ENABLE() GPIO_BOP(OUTPUT_LED_PORT) = 1 << (OUTPUT_LED_PIN + 16)
- #define OUTPUT_LED_DISABLE() GPIO_BOP(OUTPUT_LED_PORT) = 1 << (OUTPUT_LED_PIN)
- void hw_io_pin_init(void)
- {
-
- int i = 0;
- unsigned long port;
- unsigned short pin;
- /* unsigned long pupd;
- int in_size = sizeof(io_input_map) / sizeof(io_pin_t);
- int out_size = sizeof(io_output_map) / sizeof(io_pin_t);
- if (IO_PIN_INPUT_NUMBER != in_size || IO_PIN_OUTPUT_NUMBER != out_size)
- {
- while (1)
- {}
- }
- for (i = 0; i < in_size; i++)
- {
- port = (uint32_t)io_input_map[i].gpio;
- pin = 1 << io_input_map[i].pin;
- pupd = io_input_map[i].pupd;
- if (port != 0) {
- //雿輯��園�
- rcu_periph_clock_enable(rcu_periph_clock_bit(port));
- //�滨蔭IO銝箄���
- gpio_mode_set(port, GPIO_MODE_INPUT, pupd, pin);
- gpio_output_options_set(port, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, pin);
- }
- //io_input_map[i].level *= pin;
- }
- for (i = 0; i < out_size; i++)
- {
- port = (uint32_t)io_output_map[i].gpio;
- pin = 1 << io_output_map[i].pin;
- pupd = io_output_map[i].pupd;
- if (io_output_map[i].level)
- {
- GPIO_BOP(port) = pin<<16;
- } else
- {
- GPIO_BOP(port) = pin;
- }
- if (port != 0) {
- //雿輯��園�
- rcu_periph_clock_enable(rcu_periph_clock_bit(port));
- //�滨蔭IO銝箄���
- gpio_mode_set(port, GPIO_MODE_OUTPUT, pupd, pin);
- gpio_output_options_set(port, GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, pin);
- }
- }
- */
- //雿輯�颲枏枂
- {
- port = OUTPUT_ENABLE_PORT;
- pin = 1 << OUTPUT_ENABLE_PIN;
- if (port != 0) {
- //雿輯��園�
- rcu_periph_clock_enable(rcu_periph_clock_bit(port));
- //�滨蔭IO銝箄���
- gpio_mode_set(port, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, pin);
- gpio_output_options_set(port, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, pin);
- //OUTPUT_ENABLE();
- }
- }
-
- //雿輯�颲枏枂
- {
- port = OUTPUT_LED_PORT;
- pin = 1 << OUTPUT_LED_PIN;
- if (port != 0) {
- //雿輯��園�
- rcu_periph_clock_enable(rcu_periph_clock_bit(port));
- //�滨蔭IO銝箄��?
- gpio_mode_set(port, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, pin);
- gpio_output_options_set(port, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, pin);
- //OUTPUT_ENABLE();
- }
- }
- OUTPUT_DISABLE();
- OUTPUT_LED_DISABLE();
- }
- /**
- * 颲枏枂�萄像
- *
- * @author lxz
- *
- * @param index
- * @param sta
- */
- void hw_io_pin_output(unsigned short index, int sta)
- {
- if (index < IO_PIN_OUTPUT_NUMBER)
- {
- if (sta)
- {
- if (io_output_map[index].level)
- {
- GPIO_BOP(io_output_map[index].gpio) = 1 << (io_output_map[index].pin);
- } else
- {
- GPIO_BOP(io_output_map[index].gpio) = 1 << (io_output_map[index].pin+16);
- }
- } else
- {
- if (io_output_map[index].level)
- {
- GPIO_BOP(io_output_map[index].gpio) = 1 << (io_output_map[index].pin+16);
- } else
- {
- GPIO_BOP(io_output_map[index].gpio) = 1 << (io_output_map[index].pin);
- }
- }
- }
- }
- /**
- * 颲枏��萄像
- *
- * @author lxz
- *
- * @param index
- *
- * @return int
- */
- int hw_io_pin_input(unsigned short index)
- {
- if (index < IO_PIN_INPUT_NUMBER)
- {
- return (gpio_input_bit_get(io_input_map[index].gpio, (1<<io_input_map[index].pin))==
- (io_input_map[index].level));
- }
- return 0;
- }
- /**
- * 颲枏枂雿輯�
- *
- * @author lxz (2019/5/29/�其�)
- */
- void hw_io_output_enable(void)
- {
- OUTPUT_ENABLE();
- OUTPUT_LED_ENABLE();
- }
- /**
- * 颲枏枂蝳�迫
- *
- * @author lxz (2019/5/29/�其�)
- */
- void hw_io_output_disable(void)
- {
- OUTPUT_DISABLE();
- OUTPUT_LED_DISABLE();
- }
- /**
- * �瑕�IO颲枏�撘閗���𠶖���摮睃膥
- *
- * @author LXZ (062820)
- *
- * @param index
- *
- * @return void*
- */
- int hw_io_get_input_pin_infomation(unsigned short index, hw_io_infomation_t * info){
- if (index < IO_PIN_INPUT_NUMBER) {
- info->io_register = (void *)&(GPIO_ISTAT(io_input_map[index].gpio));
- info->pin_mask = 1 << io_input_map[index].pin;
- info->valid_value = io_input_map[index].level;
- return 1;
- }
- return 0;
- }
|