pleasedontcode

# GPIO Manager rev_06

Feb 19th, 2026
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: # GPIO Manager
  13.     - Source Code compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2026-02-20 04:52:58
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Initialize ESP32 DevKit V1 with configurable GPIO */
  21.     /* pins for digital I/O operations, ensuring proper */
  22.     /* pin initialization and state management during */
  23.     /* system startup and runtime. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31. /* START CODE */
  32.  
  33. // Include the GPIO configuration header file for type definitions and function declarations
  34. #include "GPIOConfig.h"
  35.  
  36. // System Requirements:
  37. // System Requirement 1: "Initialize ESP32 DevKit V1 with configurable GPIO pins for digital I/O operations,
  38. // ensuring proper pin initialization and state management during system startup and runtime."
  39.  
  40. /****** FUNCTION PROTOTYPES *****/
  41. void setup(void);
  42. void loop(void);
  43.  
  44. /**
  45.  * setup()
  46.  * Initializes the ESP32 DevKit V1 with GPIO manager and configures pins.
  47.  * This function runs once at system startup and performs:
  48.  * 1. GPIO Manager initialization
  49.  * 2. Configuration of required GPIO pins
  50.  * 3. Verification of pin configuration
  51.  */
  52. void setup(void)
  53. {
  54.     // Initialize Serial communication for debugging (optional)
  55.     Serial.begin(115200);
  56.     delay(100);
  57.    
  58.     // Initialize the GPIO Manager
  59.     // This sets up the internal GPIO management structure and resets all pins to unconfigured state
  60.     if (GPIO_Manager_Init())
  61.     {
  62.         Serial.println("GPIO Manager initialized successfully");
  63.     }
  64.     else
  65.     {
  66.         Serial.println("ERROR: GPIO Manager initialization failed");
  67.     }
  68.    
  69.     // Example: Configure GPIO pin 2 as OUTPUT with initial state LOW
  70.     // GPIO pin 2 is commonly available on ESP32 DevKit V1
  71.     if (GPIO_Configure_Pin(2, APP_GPIO_MODE_OUTPUT, APP_GPIO_STATE_LOW))
  72.     {
  73.         Serial.println("GPIO pin 2 configured as OUTPUT");
  74.     }
  75.     else
  76.     {
  77.         Serial.println("ERROR: Failed to configure GPIO pin 2");
  78.     }
  79.    
  80.     // Example: Configure GPIO pin 4 as OUTPUT with initial state LOW
  81.     if (GPIO_Configure_Pin(4, APP_GPIO_MODE_OUTPUT, APP_GPIO_STATE_LOW))
  82.     {
  83.         Serial.println("GPIO pin 4 configured as OUTPUT");
  84.     }
  85.     else
  86.     {
  87.         Serial.println("ERROR: Failed to configure GPIO pin 4");
  88.     }
  89.    
  90.     // Example: Configure GPIO pin 5 as INPUT with no initial state
  91.     // Input pins don't have initial state but the parameter is required by the function
  92.     if (GPIO_Configure_Pin(5, APP_GPIO_MODE_INPUT, APP_GPIO_STATE_LOW))
  93.     {
  94.         Serial.println("GPIO pin 5 configured as INPUT");
  95.     }
  96.     else
  97.     {
  98.         Serial.println("ERROR: Failed to configure GPIO pin 5");
  99.     }
  100.    
  101.     // Example: Configure GPIO pin 18 as INPUT with internal PULLUP
  102.     if (GPIO_Configure_Pin(18, APP_GPIO_MODE_INPUT_PULLUP, APP_GPIO_STATE_LOW))
  103.     {
  104.         Serial.println("GPIO pin 18 configured as INPUT_PULLUP");
  105.     }
  106.     else
  107.     {
  108.         Serial.println("ERROR: Failed to configure GPIO pin 18");
  109.     }
  110.    
  111.     // Display total number of configured pins
  112.     uint8_t configured_count = GPIO_Get_Configured_Count();
  113.     Serial.print("Total configured GPIO pins: ");
  114.     Serial.println(configured_count);
  115.    
  116.     delay(500);
  117. }
  118.  
  119. /**
  120.  * loop()
  121.  * Main program loop that runs continuously after setup() completes.
  122.  * This function performs:
  123.  * 1. Runtime state management checks
  124.  * 2. GPIO state monitoring
  125.  * 3. GPIO control operations
  126.  */
  127. void loop(void)
  128. {
  129.     // Perform runtime state management check to validate all configured pins
  130.     // This checks that pin states are consistent between hardware and internal management
  131.     if (GPIO_Runtime_State_Check())
  132.     {
  133.         // All configured pins are in valid state
  134.     }
  135.     else
  136.     {
  137.         // At least one pin state is invalid
  138.         Serial.println("WARNING: GPIO runtime state check detected inconsistency");
  139.     }
  140.    
  141.     // Example: Read the state of GPIO pin 5 (configured as INPUT)
  142.     GPIOState_t pin5_state = GPIO_Read_State(5);
  143.     Serial.print("GPIO pin 5 state: ");
  144.     Serial.println((pin5_state == APP_GPIO_STATE_HIGH) ? "HIGH" : "LOW");
  145.    
  146.     // Example: Read the state of GPIO pin 18 (configured as INPUT_PULLUP)
  147.     GPIOState_t pin18_state = GPIO_Read_State(18);
  148.     Serial.print("GPIO pin 18 state: ");
  149.     Serial.println((pin18_state == APP_GPIO_STATE_HIGH) ? "HIGH" : "LOW");
  150.    
  151.     // Example: Toggle GPIO pin 2 (configured as OUTPUT) every loop iteration
  152.     GPIOState_t pin2_current_state = GPIO_Read_State(2);
  153.     GPIOState_t pin2_new_state = (pin2_current_state == APP_GPIO_STATE_HIGH) ? APP_GPIO_STATE_LOW : APP_GPIO_STATE_HIGH;
  154.     if (GPIO_Set_State(2, pin2_new_state))
  155.     {
  156.         Serial.print("GPIO pin 2 set to: ");
  157.         Serial.println((pin2_new_state == APP_GPIO_STATE_HIGH) ? "HIGH" : "LOW");
  158.     }
  159.     else
  160.     {
  161.         Serial.println("ERROR: Failed to set GPIO pin 2 state");
  162.     }
  163.    
  164.     // Example: Set GPIO pin 4 to HIGH
  165.     if (GPIO_Set_State(4, APP_GPIO_STATE_HIGH))
  166.     {
  167.         Serial.println("GPIO pin 4 set to HIGH");
  168.     }
  169.     else
  170.     {
  171.         Serial.println("ERROR: Failed to set GPIO pin 4");
  172.     }
  173.    
  174.     // Example: Verify pin configuration mode for pin 2
  175.     GPIOMode_t pin2_mode = GPIO_Get_Mode(2);
  176.     Serial.print("GPIO pin 2 mode: ");
  177.     switch (pin2_mode)
  178.     {
  179.         case APP_GPIO_MODE_INPUT:
  180.             Serial.println("INPUT");
  181.             break;
  182.         case APP_GPIO_MODE_OUTPUT:
  183.             Serial.println("OUTPUT");
  184.             break;
  185.         case APP_GPIO_MODE_INPUT_PULLUP:
  186.             Serial.println("INPUT_PULLUP");
  187.             break;
  188.         case APP_GPIO_MODE_INPUT_PULLDOWN:
  189.             Serial.println("INPUT_PULLDOWN");
  190.             break;
  191.         default:
  192.             Serial.println("UNKNOWN");
  193.             break;
  194.     }
  195.    
  196.     // Example: Check if GPIO pin 4 is configured
  197.     if (GPIO_Is_Configured(4))
  198.     {
  199.         Serial.println("GPIO pin 4 is configured");
  200.     }
  201.     else
  202.     {
  203.         Serial.println("GPIO pin 4 is NOT configured");
  204.     }
  205.    
  206.     // Delay to prevent rapid loop iterations and allow observable changes
  207.     delay(2000);
  208. }
  209.  
  210. /* END CODE */
  211.  
Advertisement
Add Comment
Please, Sign In to add comment