### Installing GPIO Pin Event Handlers (Common Lisp) Source: https://github.com/shinmera/cl-gpio/blob/master/docs/index.html Shows how to install a handler function that is executed when a GPIO pin's value changes to a specified edge (e.g., falling edge). This enables reactive behavior based on external events detected by the GPIO pins. The code continuously checks for changes. ```common-lisp (defun pin-value-handler (pin value) (format T "~& ~a changed value to ~a." pin value)) (gpio:with-pin-handler (#'pin-value-handler 0 :falling) (format T "Waiting for a change on 0...") (loop (sleep 0.001))) ``` -------------------------------- ### Query GPIO Chip Information (Low-Level) Source: https://context7.com/shinmera/cl-gpio/llms.txt Provides low-level functions to retrieve hardware details about GPIO chips. This includes listing available chips, getting a chip's base pin number, its label, the total number of pins it manages, and a list of all pin numbers associated with a specific chip. ```common-lisp (use-package :cl-gpio-lli) ;; List all GPIO chips (chips) ;; => (0 100) ;; Get chip base pin number (base 0) ;; => 0 ;; Get chip label/name (label 0) ;; => "pinctrl-bcm2835" ;; Get number of pins on chip (ngpio 0) ;; => 54 ;; Get all pin numbers on a chip (chip-pins 0) ;; => (0 1 2 3 ... 53) ``` -------------------------------- ### Get Pin Name Source: https://github.com/shinmera/cl-gpio/blob/master/docs/index.html Retrieves the name or ID of a given PIN instance. ```APIDOC ## NAME ### Description Returns the pin's name or ID. ### Method EXTERNAL FUNCTION ### Endpoint N/A (Function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lisp (cl-gpio:name #) ``` ### Response #### Success Response (200) The name or ID of the pin. #### Response Example ```lisp "GPIO1" ``` ``` -------------------------------- ### Read and Write GPIO Pin Values (Common Lisp) Source: https://context7.com/shinmera/cl-gpio/llms.txt Reads or writes the digital state of a GPIO pin. Values are boolean: 't' for high (1) and 'nil' for low (0). The pin direction is automatically adjusted. Includes an example for blinking an LED. ```lisp ;; Turn on an LED connected to pin 17 (setf (value 17) t) ;; Turn off the LED (setf (value 17) nil) ;; Read button state from input pin (let ((button-pressed (value 18))) (format t "Button is ~:[released~;pressed~]%" button-pressed)) ;; Blink LED example (loop repeat 5 do (setf (value 17) t) (sleep 0.5) (setf (value 17) nil) (sleep 0.5)) ``` -------------------------------- ### Unexport GPIO Pins (Common Lisp) Source: https://context7.com/shinmera/cl-gpio/llms.txt Releases GPIO pins, making them unavailable to userspace and clearing them from the cache. Supports unexporting single or multiple pins, and includes an example for cleaning up all exported pins. ```lisp ;; Unexport single pin (unexport 17) ;; Unexport multiple pins (unexport 17 18 23 24) ;; Clean up all exported pins (mapc #'unexport (mapcar #'name (pins))) ``` -------------------------------- ### List Available Pins Source: https://github.com/shinmera/cl-gpio/blob/master/docs/index.html Returns a list of all GPIO pins that are available on the system. ```APIDOC ## AVAILABLE-PINS ### Description Return a list of all available GPIO pins on the system. ### Method EXTERNAL FUNCTION ### Endpoint N/A (Function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lisp (cl-gpio-lli:available-pins) ``` ### Response #### Success Response (200) A list of available GPIO pin identifiers. #### Response Example ```lisp (0 1 2 3 4 5 ...) ``` ``` -------------------------------- ### List Exported Pins Source: https://github.com/shinmera/cl-gpio/blob/master/docs/index.html Returns a list of all currently available or exported PIN instances on the system. ```APIDOC ## PINS ### Description Returns a list of available/exported PIN instances. ### Method EXTERNAL FUNCTION ### Endpoint N/A (Function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lisp (cl-gpio:pins) ``` ### Response #### Success Response (200) A list of available/exported PIN instances. #### Response Example ```lisp (# #) ``` ``` -------------------------------- ### Retrieving All Available GPIO Pins (Common Lisp) Source: https://github.com/shinmera/cl-gpio/blob/master/docs/index.html This function retrieves a list of all available GPIO pins on the system, represented as PIN instances. This is a foundational step for managing and interacting with multiple GPIO pins. ```common-lisp (gpio:all-pins) ``` -------------------------------- ### Export GPIO Pins Source: https://github.com/shinmera/cl-gpio/blob/master/docs/index.html This code snippet demonstrates how to export GPIO pins, which may be necessary if `gpio:pins` returns NIL. It iterates through a range of pin numbers and exports each one. Replace '26' with the actual number of pins available on your system. ```common-lisp (loop for i from 0 to 26 do (gpio:export i)) ``` -------------------------------- ### Low-Level File Operations for GPIO Pins Source: https://context7.com/shinmera/cl-gpio/llms.txt Enables direct filesystem operations for managing GPIO pins, offering maximum performance for advanced use cases. This includes exporting and unexporting pins, setting their direction (input/output), writing values to them, and reading their current values. ```common-lisp (use-package :cl-gpio-lli) ;; Export pin at low level (export-pin 17) ;; Set pin direction (setf (direction 17) :out) ;; Write value with minimal overhead (setf (value 17) t) ;; Read value directly (value 17) ;; => T ;; Unexport pin (unexport-pin 17) ``` -------------------------------- ### Export GPIO Pins (Common Lisp) Source: https://context7.com/shinmera/cl-gpio/llms.txt Exports GPIO pins, making them accessible from userspace. Returns pin instances and caches them for later use. Handles exporting single or multiple pins. ```lisp (use-package :cl-gpio) ;; Export single pin (export 17) ;; => (#) ;; Export multiple pins at once (export 17 18 23 24) ;; => (# # # #) ;; Store pin reference for later use (defvar *led-pin* (first (export 17))) ``` -------------------------------- ### Export Pins Source: https://github.com/shinmera/cl-gpio/blob/master/docs/index.html Exports the specified pins and returns a list of their corresponding PIN instances. This function ensures that the pins are ready for use. ```APIDOC ## EXPORT ### Description Exports the specified pins and returns a list of according PIN instances. ### Method EXTERNAL FUNCTION ### Endpoint N/A (Function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lisp (cl-gpio:export 1 2 3) ``` ### Response #### Success Response (200) A list of exported PIN instances. #### Response Example ```lisp (# # #) ``` ``` -------------------------------- ### List Available and Exported GPIO Pins (Common Lisp) Source: https://context7.com/shinmera/cl-gpio/llms.txt Provides functions to list all currently exported (active) GPIO pins on the system and all available pins. Can also retrieve just the pin numbers. ```lisp ;; Get all exported (active) pins (pins) ;; => (# #) ;; Get all available pins on the system (all-pins) ;; => (# # ... #) ;; Get pin numbers only (mapcar #'name (pins)) ;; => (17 18) ``` -------------------------------- ### Enumerate Available GPIO Pins Source: https://github.com/shinmera/cl-gpio/blob/master/docs/index.html This function enumerates a list of all available GPIO pins on the system. It returns NIL if no pins are found or if they need to be exported first. ```common-lisp (gpio:pins) ``` -------------------------------- ### GPIO Root Directory Source: https://github.com/shinmera/cl-gpio/blob/master/docs/index.html The root directory for GPIO system devices, typically '/sys/class/gpio/'. ```APIDOC #\*GPIO-ROOT\* ### Description The root directory of the GPIO system devices. Should be /sys/class/gpio/ ### Method EXTERNAL SPECIAL-VARIABLE ### Endpoint N/A ### Parameters None ### Request Example ```lisp cl-gpio-lli:*gpio-root* ``` ### Response #### Success Response (200) The path to the GPIO root directory. #### Response Example ```lisp "/sys/class/gpio/" ``` ``` -------------------------------- ### With Pin Handler Source: https://github.com/shinmera/cl-gpio/blob/master/docs/index.html A macro that allows setting up a handler function to be called when a PIN's value changes during the evaluation of a body of code. ```APIDOC ## WITH-PIN-HANDLER ### Description Shorthand to call a handler function on PIN value change during the evaluation of BODY. ### Method EXTERNAL MACRO ### Endpoint N/A (Macro invocation) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lisp (cl-gpio:with-pin-handler (lambda (pin value) (format t "Pin ~a changed to ~a~%" pin value)) # :edge :both) ``` ### Response #### Success Response (200) N/A (Macro execution) #### Response Example N/A ``` -------------------------------- ### Monitor GPIO Pin Changes with Callbacks (SBCL) Source: https://context7.com/shinmera/cl-gpio/llms.txt Registers a callback function to execute when a pin's value changes. This feature is exclusive to SBCL. It takes a handler function, the pin number, and optional edge detection parameters. The handler receives the pin object and its new value. The macro activates the handler within its dynamic scope. ```common-lisp (with-pin-handler ((lambda (pin new-value) (format t "Pin ~a changed to ~a~%" (name pin) new-value)) 18 :both nil) ;; Handler active during this body (loop repeat 10 do (sleep 1))) ;; Count button presses over 30 seconds (let ((press-count 0)) (with-pin-handler ((lambda (pin new-value) (when new-value (incf press-count))) 18 :rising nil) (sleep 30) (format t "Button pressed ~a times~%" press-count))) ;; Use call-with-pin-handler for more control (call-with-pin-handler (lambda () (loop (sleep 1))) ; Main function (lambda (pin value) (format t "~a ~a~%" pin value)) ; Handler 18 ; Pin :both ; Edge nil) ; Active-low ``` -------------------------------- ### Configure GPIO Pin Edge Detection (Common Lisp) Source: https://context7.com/shinmera/cl-gpio/llms.txt Configures interrupt edge detection for input pins. Valid settings are :none, :rising, :falling, or :both. This allows for reacting to specific signal changes on a pin. ```lisp ;; Detect rising edge (button press) (setf (edge 18) :rising) ;; Detect both edges (any change) (setf (edge 18) :both) ;; Disable edge detection (setf (edge 18) :none) ;; Check current edge configuration (edge 18) ;; => :BOTH ``` -------------------------------- ### Accessing and Modifying GPIO Pin Properties (Common Lisp) Source: https://github.com/shinmera/cl-gpio/blob/master/docs/index.html Demonstrates how to set the direction and access the active-low state of a GPIO pin. It also shows how reading or setting a pin's value automatically adjusts its direction. This functionality is essential for basic GPIO control. ```common-lisp (setf (gpio:direction 0) :out) (gpio:active-low 0) (gpio:value 0) (setf (gpio:value 0) T) ``` -------------------------------- ### Set Pin Value Source: https://github.com/shinmera/cl-gpio/blob/master/docs/index.html Sets the I/O value of the pin. This is a SETF-able accessor. The pin will be exported if it is not already, and its direction adjusted. ```APIDOC ## (SETF VALUE) ### Description Sets the pin's I/O value. The pin's I/O direction is automatically adjusted if necessary. ### Method EXTERNAL FUNCTION (SETF) ### Endpoint N/A (Function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lisp (setf (cl-gpio:value #) 1) ``` ### Response #### Success Response (200) Returns the value that was set. #### Response Example ```lisp 1 ``` ``` -------------------------------- ### Waiting for GPIO Pin Value Changes (SBCL Specific) (Common Lisp) Source: https://github.com/shinmera/cl-gpio/blob/master/docs/index.html This snippet illustrates how to wait for a specific edge (change) on a GPIO pin and then retrieve its new value. This feature is specific to the SBCL Common Lisp implementation and is useful for event-driven GPIO interactions. ```common-lisp (progn (gpio:await-value 0) (format T "Whoah, 0's edge is ~a to ~:[0~;1~]" (edge 0) (value 0))) ``` -------------------------------- ### Configure GPIO Active-Low Logic (Common Lisp) Source: https://context7.com/shinmera/cl-gpio/llms.txt Inverts the logic level of a GPIO pin. When active-low is set to 't', a low voltage (0) is considered active and a high voltage (1) inactive. Useful for devices like pull-up buttons. ```lisp ;; Enable active-low for a pull-up button (setf (active-low 18) t) ;; Now reading the pin will return t when button grounds the pin (value 18) ;; => T (when button pressed and pin is grounded) ;; Disable active-low (normal logic) (setf (active-low 18) nil) ``` -------------------------------- ### Access Pin Value Source: https://github.com/shinmera/cl-gpio/blob/master/docs/index.html Accesses the pin's I/O value. If the pin is not exported, it will be automatically exported. The I/O direction is adjusted as needed. ```APIDOC ## VALUE ### Description Accesses the pin's I/O value. If the pin does not yet exist or is not exported, it will be. The pin's I/O direction is automatically adjusted if necessary depending on whether the value is read or set by SETF. The value returned by this is never cached. ### Method EXTERNAL FUNCTION ### Endpoint N/A (Function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lisp ;; Read value (cl-gpio:value #) ;; Set value (setf (cl-gpio:value #) 1) ``` ### Response #### Success Response (200) Returns the current I/O value of the pin (e.g., 0 or 1). #### Response Example ```lisp 1 ``` ``` -------------------------------- ### Wait for Pin Value Changes (SBCL Only) (Common Lisp) Source: https://context7.com/shinmera/cl-gpio/llms.txt Blocks execution until a GPIO pin has a readable value, with optional timeout support. This function is specific to the SBCL implementation. Useful for synchronizing with external events. ```lisp ;; Wait indefinitely for pin to be readable (let ((pin (first (export 18)))) (setf (edge pin) :both) (await-value pin)) ;; Wait with 5-second timeout (if (await-value 18 5) (format t "Pin value available: ~a~%" (value 18)) (format t "Timeout waiting for pin~%")) ``` -------------------------------- ### Set Active Low Source: https://github.com/shinmera/cl-gpio/blob/master/docs/index.html Sets whether a GPIO pin has an active low setting. This is a SETF-able accessor. ```APIDOC ## (SETF ACTIVE-LOW) ### Description Sets the active low status of the GPIO pin. ### Method EXTERNAL FUNCTION (SETF) ### Endpoint N/A (Function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lisp (setf (cl-gpio-lli:active-low #) T) ``` ### Response #### Success Response (200) The value that was set (NIL or T). #### Response Example ```lisp T ``` ``` -------------------------------- ### Check Active Low Source: https://github.com/shinmera/cl-gpio/blob/master/docs/index.html Accessor to determine if a GPIO pin has an active low setting. The value should be NIL or T. ```APIDOC ## ACTIVE-LOW ### Description Accessor to whether the GPIO pin has an active low. The value should be either NIL or T. ### Method EXTERNAL FUNCTION ### Endpoint N/A (Function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lisp (cl-gpio-lli:active-low #) ``` ### Response #### Success Response (200) NIL or T, indicating if the pin is active low. #### Response Example ```lisp T ``` ``` -------------------------------- ### Set GPIO Pin Direction (Common Lisp) Source: https://context7.com/shinmera/cl-gpio/llms.txt Sets the direction of a GPIO pin to either input (:in) or output (:out). The direction can be explicitly controlled or is automatically set during read/write operations. Works with pin numbers or pin objects. ```lisp ;; Set pin as output for controlling an LED (setf (direction 17) :out) ;; Set pin as input for reading a button state (setf (direction 18) :in) ;; Check current direction (direction 17) ;; => :OUT ;; Using a pin object (let ((pin (first (export 23)))) (setf (direction pin) :out)) ``` -------------------------------- ### Unexport Pins Source: https://github.com/shinmera/cl-gpio/blob/master/docs/index.html Unexports the specified pins and invalidates their cache. This releases the pins for other processes or re-initialization. ```APIDOC ## UNEXPORT ### Description Unexport the specified pins and invalidate their cache. ### Method EXTERNAL FUNCTION ### Endpoint N/A (Function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lisp (cl-gpio:unexport # #) ``` ### Response #### Success Response (200) Returns NIL. #### Response Example ```lisp NIL ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.