test_suite_flowcontroll.cpp 4.0 KB

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