Skip to content

mytechnotalent/ESP32-C3_Button_Driver

Repository files navigation

FREE Reverse Engineering Self-Study Course HERE

VIDEO PROMO HERE


ESP32-C3 Button Driver

An ESP32-C3 button driver written entirely in RISC-V Assembler.


Install ESP Toolchain

Windows Installer HERE

Linux and macOS Installer HERE


Hardware

ESP32-C3 Super Mini BUY

USB-C to USB Cable BUY

Complete Component Kit for Raspberry Pi BUY

10pc 25v 1000uF Capacitor BUY

10% PiShop DISCOUNT CODE - KVPE_HS320548_10PC


Circuit Diagram

3.3V -------- [Button] -------- GPIO1 -------- [1kΩ] -------- GND
                                                                  
GPIO0 -------- [220Ω] -------- [LED+] -------- [LED-] -------- GND

Circuit Details

  • Button: Connects GPIO1 to 3.3V when pressed (active-high)
  • 1kΩ Pull-down Resistor: Keeps GPIO1 LOW when button not pressed
  • LED: Mirrors button state - ON when pressed, OFF when released
  • 220Ω Resistor: Current limiting resistor for LED protection

Functionality

  • LED mirrors button state in real-time
  • Button pressed → LED ON (GPIO1 HIGH → GPIO0 HIGH)
  • Button released → LED OFF (GPIO1 LOW → GPIO0 LOW)
  • Simple direct state transfer without debouncing or toggling

main.s Code

/*
 * FILE: main.s
 *
 * DESCRIPTION:
 * ESP32-C3 Bare-Metal Button-Controlled LED Application.
 *
 * AUTHOR: Kevin Thomas
 * CREATION DATE: November 14, 2025
 * UPDATE DATE: November 29, 2025
 */

.include "inc/registers.inc"

/**
 * Initialize the .text.init section.
 * The .text.init section contains executable code.
 */
.section .text

/**
 * @brief   Main application entry point.
 *
 * @details Button-controlled LED using gpio_read and gpio_write functions.
 *          GPIO1 input (button) controls GPIO0 output (LED).
 *          Active-high: button pressed = LED ON.
 *
 * @param   None
 * @retval  None
 */
.global main
.type main, %function
main:
  # Initialize GPIO0 as output
  li    a0, 0                                    # pin number 0
  jal   gpio_output_enable                       # enable GPIO0 output
  
  # Initialize GPIO1 as input
  li    a0, 1                                    # pin number 1
  jal   gpio_input_enable                        # enable GPIO1 input
  
.loop:
  # Read GPIO1 (button)
  li    a0, 1                                    # pin number 1
  jal   gpio_read                                # read button state (0 or 1)
  
  # Write result to GPIO0 (LED)
  mv    a1, a0                                   # move result to a1
  li    a0, 0                                    # pin number 0
  jal   gpio_write                               # write to LED
  
  j     .loop                                    # loop forever
.size main, .-main

License

Apache License 2.0

About

An ESP32-C3 button driver written entirely in RISC-V Assembler.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published