Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: # GPIO Management
- - Source Code compiled for: ESP32 DevKit V1
- - Source Code created on: 2026-02-20 04:50:48
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Initialize ESP32 DevKit V1 with configurable GPIO */
- /* pins for digital I/O operations, ensuring proper */
- /* pin initialization and state management during */
- /* system startup and runtime. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- // Include the GPIO configuration header file for type definitions and function declarations
- #include "GPIOConfig.h"
- // System Requirements:
- // System Requirement 1: "Initialize ESP32 DevKit V1 with configurable GPIO pins for digital I/O operations,
- // ensuring proper pin initialization and state management during system startup and runtime."
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /**
- * setup()
- * Initializes the ESP32 DevKit V1 with GPIO manager and configures pins.
- * This function runs once at system startup and performs:
- * 1. GPIO Manager initialization
- * 2. Configuration of required GPIO pins
- * 3. Verification of pin configuration
- */
- void setup(void)
- {
- // Initialize Serial communication for debugging (optional)
- Serial.begin(115200);
- delay(100);
- // Initialize the GPIO Manager
- // This sets up the internal GPIO management structure and resets all pins to unconfigured state
- if (GPIO_Manager_Init())
- {
- Serial.println("GPIO Manager initialized successfully");
- }
- else
- {
- Serial.println("ERROR: GPIO Manager initialization failed");
- }
- // Example: Configure GPIO pin 2 as OUTPUT with initial state LOW
- // GPIO pin 2 is commonly available on ESP32 DevKit V1
- if (GPIO_Configure_Pin(2, APP_GPIO_MODE_OUTPUT, APP_GPIO_STATE_LOW))
- {
- Serial.println("GPIO pin 2 configured as OUTPUT");
- }
- else
- {
- Serial.println("ERROR: Failed to configure GPIO pin 2");
- }
- // Example: Configure GPIO pin 4 as OUTPUT with initial state LOW
- if (GPIO_Configure_Pin(4, APP_GPIO_MODE_OUTPUT, APP_GPIO_STATE_LOW))
- {
- Serial.println("GPIO pin 4 configured as OUTPUT");
- }
- else
- {
- Serial.println("ERROR: Failed to configure GPIO pin 4");
- }
- // Example: Configure GPIO pin 5 as INPUT with no initial state
- // Input pins don't have initial state but the parameter is required by the function
- if (GPIO_Configure_Pin(5, APP_GPIO_MODE_INPUT, APP_GPIO_STATE_LOW))
- {
- Serial.println("GPIO pin 5 configured as INPUT");
- }
- else
- {
- Serial.println("ERROR: Failed to configure GPIO pin 5");
- }
- // Example: Configure GPIO pin 18 as INPUT with internal PULLUP
- if (GPIO_Configure_Pin(18, APP_GPIO_MODE_INPUT_PULLUP, APP_GPIO_STATE_LOW))
- {
- Serial.println("GPIO pin 18 configured as INPUT_PULLUP");
- }
- else
- {
- Serial.println("ERROR: Failed to configure GPIO pin 18");
- }
- // Display total number of configured pins
- uint8_t configured_count = GPIO_Get_Configured_Count();
- Serial.print("Total configured GPIO pins: ");
- Serial.println(configured_count);
- delay(500);
- }
- /**
- * loop()
- * Main program loop that runs continuously after setup() completes.
- * This function performs:
- * 1. Runtime state management checks
- * 2. GPIO state monitoring
- * 3. GPIO control operations
- */
- void loop(void)
- {
- // Perform runtime state management check to validate all configured pins
- // This checks that pin states are consistent between hardware and internal management
- if (GPIO_Runtime_State_Check())
- {
- // All configured pins are in valid state
- }
- else
- {
- // At least one pin state is invalid
- Serial.println("WARNING: GPIO runtime state check detected inconsistency");
- }
- // Example: Read the state of GPIO pin 5 (configured as INPUT)
- GPIOState_t pin5_state = GPIO_Read_State(5);
- Serial.print("GPIO pin 5 state: ");
- Serial.println((pin5_state == APP_GPIO_STATE_HIGH) ? "HIGH" : "LOW");
- // Example: Read the state of GPIO pin 18 (configured as INPUT_PULLUP)
- GPIOState_t pin18_state = GPIO_Read_State(18);
- Serial.print("GPIO pin 18 state: ");
- Serial.println((pin18_state == APP_GPIO_STATE_HIGH) ? "HIGH" : "LOW");
- // Example: Toggle GPIO pin 2 (configured as OUTPUT) every loop iteration
- GPIOState_t pin2_current_state = GPIO_Read_State(2);
- GPIOState_t pin2_new_state = (pin2_current_state == APP_GPIO_STATE_HIGH) ? APP_GPIO_STATE_LOW : APP_GPIO_STATE_HIGH;
- if (GPIO_Set_State(2, pin2_new_state))
- {
- Serial.print("GPIO pin 2 set to: ");
- Serial.println((pin2_new_state == APP_GPIO_STATE_HIGH) ? "HIGH" : "LOW");
- }
- else
- {
- Serial.println("ERROR: Failed to set GPIO pin 2 state");
- }
- // Example: Set GPIO pin 4 to HIGH
- if (GPIO_Set_State(4, APP_GPIO_STATE_HIGH))
- {
- Serial.println("GPIO pin 4 set to HIGH");
- }
- else
- {
- Serial.println("ERROR: Failed to set GPIO pin 4");
- }
- // Example: Verify pin configuration mode for pin 2
- GPIOMode_t pin2_mode = GPIO_Get_Mode(2);
- Serial.print("GPIO pin 2 mode: ");
- switch (pin2_mode)
- {
- case APP_GPIO_MODE_INPUT:
- Serial.println("INPUT");
- break;
- case APP_GPIO_MODE_OUTPUT:
- Serial.println("OUTPUT");
- break;
- case APP_GPIO_MODE_INPUT_PULLUP:
- Serial.println("INPUT_PULLUP");
- break;
- case APP_GPIO_MODE_INPUT_PULLDOWN:
- Serial.println("INPUT_PULLDOWN");
- break;
- default:
- Serial.println("UNKNOWN");
- break;
- }
- // Example: Check if GPIO pin 4 is configured
- if (GPIO_Is_Configured(4))
- {
- Serial.println("GPIO pin 4 is configured");
- }
- else
- {
- Serial.println("GPIO pin 4 is NOT configured");
- }
- // Delay to prevent rapid loop iterations and allow observable changes
- delay(2000);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment