test_suite_flowcontroll.cpp 3.9 KB

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