user_main.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* main.c -- MQTT client example
  2. *
  3. * Copyright (c) 2014-2015, Tuan PM <tuanpm at live dot com>
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * * Redistributions of source code must retain the above copyright notice,
  10. * this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Redis nor the names of its contributors may be used
  15. * to endorse or promote products derived from this software without
  16. * specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  22. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include "esp_common.h"
  31. #include "driver/uart.h"
  32. #include "driver/spi_interface.h"
  33. #include "gpio.h"
  34. #include "log/esp_log.h"
  35. #include "gdbstub/gdbstub.h"
  36. #include "hal/lsm6ds3.h"
  37. #include "hal/max17043.h"
  38. #include "hal/lps25hb.h"
  39. #include "hal/ws2812.h"
  40. #include "user_config.h"
  41. static const char* TAG = "main.c";
  42. // void wifi_handle_event_cb(System_Event_t *evt)
  43. // {
  44. // switch(evt->event)
  45. // {
  46. // case EVENT_STAMODE_CONNECTED:
  47. // break;
  48. // case EVENT_STAMODE_DISCONNECTED:
  49. // break;
  50. // case EVENT_STAMODE_AUTHMODE_CHANGE:
  51. // break;
  52. // case EVENT_STAMODE_GOT_IP:
  53. // break;
  54. // case EVENT_SOFTAPMODE_PROBEREQRECVED:
  55. // break;
  56. // case EVENT_SOFTAPMODE_STACONNECTED:
  57. // break;
  58. // case EVENT_SOFTAPMODE_STADISCONNECTED:
  59. // break;
  60. // default:
  61. // break;
  62. // }
  63. // }
  64. #define DEBOUNCEDELAY 10 // ms
  65. #define SHDN_MUX PERIPHS_IO_MUX_GPIO4_U // GPIO 4
  66. #define PBA_MUX PERIPHS_IO_MUX_GPIO5_U // GPIO 5
  67. #define PBB_MUX PERIPHS_IO_MUX_GPIO2_U // GPIO 2
  68. #define STATLED_MUX PERIPHS_IO_MUX_GPIO2_U // GPIO 0
  69. #define SHDN_FUNC FUNC_GPIO4
  70. #define PBA_FUNC FUNC_GPIO5
  71. #define PBB_FUNC FUNC_GPIO2
  72. #define STATLED_FUNC FUNC_GPIO0
  73. #define SHDN 4
  74. #define PBA 5
  75. #define PBB 2
  76. #define STATLED 0
  77. void ICACHE_FLASH_ATTR app_init(void)
  78. {
  79. uart_init(BIT_RATE_115200, BIT_RATE_115200, DISABLE_UART1);
  80. ESP_LOGI(TAG, "Starting LSM6DS3 Demo\n");
  81. ESP_LOGI(TAG, "WiFi Testing \n");
  82. //while(true)
  83. {
  84. LSM6DS3_Enable_I2C_Bridge(1);
  85. uint16_t x = max17043_getVoltage();
  86. ESP_LOGI(TAG, "MAX17043 Voltage %d", x);
  87. uint8_t y;
  88. LPS25HB_Get_DeviceID(&y);
  89. ESP_LOGI(TAG, "DEVICEID %x", y);
  90. // uint8_t i;
  91. // for(i=0;i<8;i++)
  92. // ESP_LOGI(TAG, "RX SPI Value: %x", data[i]);
  93. //os_delay_us(1000000);
  94. system_soft_wdt_feed();
  95. }
  96. //while(true)
  97. {
  98. ESP_LOGI(TAG, "Setting WS2812B");
  99. PIN_FUNC_SELECT(STATLED_MUX, STATLED_FUNC);
  100. gpio_output_set(BIT(SHDN), BIT(STATLED), (BIT(SHDN)|BIT(STATLED)), (BIT(PBA)|BIT(PBB)));
  101. WS2812_SetColor(WS2812_ORANGE, WS2812_PULSE);
  102. }
  103. // wifi_set_opmode(STATION_MODE);
  104. // wifi_station_ap_number_set(MAX_APS);
  105. // wifi_station_set_auto_connect(true);
  106. //
  107. // wifi_station_get_ap_info()
  108. // wifi_station_ap_change()
  109. // wifi_staiton_get_current_ap_id()
  110. // wifi_set_sleep_type(MODEM_SLEEP_T);
  111. // wifi_enable_gpio_wakeup()
  112. //
  113. // if (wifi_station_get_config())
  114. // os_printf("zero wifi_config\n");
  115. // else
  116. // os_printf("there is a stored config");
  117. }
  118. void user_init(void)
  119. {
  120. wifi_set_opmode(STATION_MODE);
  121. wifi_station_ap_number_set(5);
  122. system_init_done_cb(app_init);
  123. }