test_suite_flowcontroll.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include <unity.h>
  2. #include "components/jomjol-flowcontroll/test_flowpostprocessing.cpp"
  3. // SD-Card ////////////////////
  4. #include "nvs_flash.h"
  5. #include "esp_vfs_fat.h"
  6. #include "sdmmc_cmd.h"
  7. #include "driver/sdmmc_host.h"
  8. #include "driver/sdmmc_defs.h"
  9. static const char *TAGMAIN = "main";
  10. #define __SD_USE_ONE_LINE_MODE__
  11. #include "server_GPIO.h"
  12. void initGPIO()
  13. {
  14. gpio_config_t io_conf;
  15. //set as output mode
  16. io_conf.mode = gpio_mode_t::GPIO_MODE_INPUT;
  17. //bit mask of the pins that you want to set,e.g.GPIO18/19
  18. io_conf.pull_down_en = gpio_pulldown_t::GPIO_PULLDOWN_ENABLE;
  19. //set pull-up mode
  20. io_conf.pull_up_en = gpio_pullup_t::GPIO_PULLUP_DISABLE;
  21. //configure GPIO with the given settings
  22. gpio_config(&io_conf);
  23. }
  24. bool Init_NVS_SDCard()
  25. {
  26. esp_err_t ret = nvs_flash_init();
  27. if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
  28. ESP_ERROR_CHECK(nvs_flash_erase());
  29. ret = nvs_flash_init();
  30. }
  31. ////////////////////////////////////////////////
  32. ESP_LOGI(TAGMAIN, "Using SDMMC peripheral");
  33. sdmmc_host_t host = SDMMC_HOST_DEFAULT();
  34. // This initializes the slot without card detect (CD) and write protect (WP) signals.
  35. // Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
  36. sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
  37. // To use 1-line SD mode, uncomment the following line:
  38. #ifdef __SD_USE_ONE_LINE_MODE__
  39. slot_config.width = 1;
  40. #endif
  41. // GPIOs 15, 2, 4, 12, 13 should have external 10k pull-ups.
  42. // Internal pull-ups are not sufficient. However, enabling internal pull-ups
  43. // does make a difference some boards, so we do that here.
  44. gpio_set_pull_mode(GPIO_NUM_15, GPIO_PULLUP_ONLY); // CMD, needed in 4- and 1- line modes
  45. gpio_set_pull_mode(GPIO_NUM_2, GPIO_PULLUP_ONLY); // D0, needed in 4- and 1-line modes
  46. #ifndef __SD_USE_ONE_LINE_MODE__
  47. gpio_set_pull_mode(GPIO_NUM_4, GPIO_PULLUP_ONLY); // D1, needed in 4-line mode only
  48. gpio_set_pull_mode(GPIO_NUM_12, GPIO_PULLUP_ONLY); // D2, needed in 4-line mode only
  49. #endif
  50. gpio_set_pull_mode(GPIO_NUM_13, GPIO_PULLUP_ONLY); // D3, needed in 4- and 1-line modes
  51. // Options for mounting the filesystem.
  52. // If format_if_mount_failed is set to true, SD card will be partitioned and
  53. // formatted in case when mounting fails.
  54. esp_vfs_fat_sdmmc_mount_config_t mount_config = {
  55. .format_if_mount_failed = false,
  56. .max_files = 5,
  57. .allocation_unit_size = 16 * 1024
  58. };
  59. // Use settings defined above to initialize SD card and mount FAT filesystem.
  60. // Note: esp_vfs_fat_sdmmc_mount is an all-in-one convenience function.
  61. // Please check its source code and implement error recovery when developing
  62. // production applications.
  63. sdmmc_card_t* card;
  64. ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
  65. if (ret != ESP_OK) {
  66. if (ret == ESP_FAIL) {
  67. ESP_LOGE(TAGMAIN, "Failed to mount filesystem. "
  68. "If you want the card to be formatted, set format_if_mount_failed = true.");
  69. } else {
  70. ESP_LOGE(TAGMAIN, "Failed to initialize the card (%s). "
  71. "Make sure SD card lines have pull-up resistors in place.", esp_err_to_name(ret));
  72. }
  73. return false;
  74. }
  75. sdmmc_card_print_info(stdout, card);
  76. return true;
  77. }
  78. /**
  79. * @brief startup the test. Like a test-suite
  80. * all test methods must be called here
  81. */
  82. extern "C" void app_main()
  83. {
  84. initGPIO();
  85. Init_NVS_SDCard();
  86. UNITY_BEGIN();
  87. RUN_TEST(test_doFlow);
  88. UNITY_END();
  89. }