gpio16.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * ESPRSSIF MIT License
  3. *
  4. * Copyright (c) 2016 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
  5. *
  6. * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
  7. * it is free of charge, to any person obtaining a copy of this software and associated
  8. * documentation files (the "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
  11. * to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all copies or
  14. * substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. */
  24. #include "ets_sys.h"
  25. #include "osapi.h"
  26. #include "driver/gpio16.h"
  27. void ICACHE_FLASH_ATTR
  28. gpio16_output_conf(void)
  29. {
  30. WRITE_PERI_REG(PAD_XPD_DCDC_CONF,
  31. (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); // mux configuration for XPD_DCDC to output rtc_gpio0
  32. WRITE_PERI_REG(RTC_GPIO_CONF,
  33. (READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); //mux configuration for out enable
  34. WRITE_PERI_REG(RTC_GPIO_ENABLE,
  35. (READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe) | (uint32)0x1); //out enable
  36. }
  37. void ICACHE_FLASH_ATTR
  38. gpio16_output_set(uint8 value)
  39. {
  40. WRITE_PERI_REG(RTC_GPIO_OUT,
  41. (READ_PERI_REG(RTC_GPIO_OUT) & (uint32)0xfffffffe) | (uint32)(value & 1));
  42. }
  43. void ICACHE_FLASH_ATTR
  44. gpio16_input_conf(void)
  45. {
  46. WRITE_PERI_REG(PAD_XPD_DCDC_CONF,
  47. (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); // mux configuration for XPD_DCDC and rtc_gpio0 connection
  48. WRITE_PERI_REG(RTC_GPIO_CONF,
  49. (READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); //mux configuration for out enable
  50. WRITE_PERI_REG(RTC_GPIO_ENABLE,
  51. READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe); //out disable
  52. }
  53. uint8 ICACHE_FLASH_ATTR
  54. gpio16_input_get(void)
  55. {
  56. return (uint8)(READ_PERI_REG(RTC_GPIO_IN_DATA) & 1);
  57. }