user_main.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. void ICACHE_FLASH_ATTR app_init(void)
  65. {
  66. uart_init(BIT_RATE_115200, BIT_RATE_115200, DISABLE_UART1);
  67. ESP_LOGI(TAG, "LSM6DS3, MAX17043, and LPS25HB Testing...");
  68. //while(true)
  69. {
  70. LSM6DS3_Enable_I2C_Bridge(1);
  71. uint16_t x = max17043_getVoltage();
  72. ESP_LOGI(TAG, "MAX17043 Voltage %d", x);
  73. uint8_t y;
  74. LPS25HB_Get_DeviceID(&y);
  75. ESP_LOGI(TAG, "DEVICEID %x", y);
  76. // uint8_t i;
  77. // for(i=0;i<8;i++)
  78. // ESP_LOGI(TAG, "RX SPI Value: %x", data[i]);
  79. //os_delay_us(1000000);
  80. system_soft_wdt_feed();
  81. }
  82. ESP_LOGI(TAG, "WS2812B Testing...");
  83. //while(true)
  84. {
  85. ESP_LOGI(TAG, "Setting WS2812B");
  86. WS2812_SetColor(WS2812_ORANGE, WS2812_PULSE);
  87. }
  88. ESP_LOGI(TAG, "Encoder IO Testing...")
  89. {
  90. Encoder_InitIO();
  91. //Encoder_SetSwitchCallback(os_printf("SWITCH_A"), os_printf("SWITCH_B"));
  92. //Encoder_SetIMUCallback(os_printf("IMU"));
  93. LSM6DS3_EnableMotion();
  94. Encoder_EnableIOInterrupts();
  95. }
  96. }
  97. void user_init(void)
  98. {
  99. wifi_set_opmode(STATION_MODE);
  100. wifi_station_ap_number_set(5);
  101. system_init_done_cb(app_init);
  102. }