PikaPiZero_KEY.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "PikaPiZero_KEY.h"
  2. #include "main.h"
  3. int PikaPiZero_KEY_get(PikaObj *self){
  4. /* SW0 */
  5. if(LL_GPIO_IsInputPinSet(GPIOA, LL_GPIO_PIN_0)){
  6. return 0;
  7. }
  8. /* SW1 */
  9. if(!LL_GPIO_IsInputPinSet(GPIOA, LL_GPIO_PIN_15)){
  10. return 1;
  11. }
  12. /* SW2 */
  13. if(!LL_GPIO_IsInputPinSet(GPIOB, LL_GPIO_PIN_6)){
  14. return 2;
  15. }
  16. /* SW3 */
  17. if(!LL_GPIO_IsInputPinSet(GPIOC, LL_GPIO_PIN_13)){
  18. return 3;
  19. }
  20. return -1;
  21. }
  22. void PikaPiZero_KEY_init(PikaObj *self){
  23. __HAL_RCC_GPIOA_CLK_ENABLE();
  24. __HAL_RCC_GPIOB_CLK_ENABLE();
  25. __HAL_RCC_GPIOC_CLK_ENABLE();
  26. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  27. /*Configure GPIO*/
  28. /* SW0 */
  29. GPIO_InitStruct.Pin = LL_GPIO_PIN_0;
  30. GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
  31. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  32. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  33. LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  34. /* SW1 */
  35. GPIO_InitStruct.Pin = LL_GPIO_PIN_15;
  36. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  37. LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  38. /* SW3 */
  39. GPIO_InitStruct.Pin = LL_GPIO_PIN_13;
  40. LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  41. /* SW2 */
  42. GPIO_InitStruct.Pin = LL_GPIO_PIN_6;
  43. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  44. }