66 lines
1.7 KiB
C
66 lines
1.7 KiB
C
/*
|
|
* gpio_devmem.h — Direct GPIO control via /dev/mem for KL630
|
|
*
|
|
* Purpose:
|
|
* Bypass kernel driver pinmux conflicts by directly accessing GPIO registers
|
|
* in physical memory. Used when J15 GPIO pins are already claimed by another
|
|
* kernel module (e.g., dh2228fv display driver).
|
|
*
|
|
* Register Layout (KL630, GPIO_C base = 0x402E0000):
|
|
* +0x0000: GPIOD_PSR — Port Status Register (read-only, shows pin states)
|
|
* +0x0004: GPIOD_PDDR — Port Data Direction Register (0=input, 1=output)
|
|
* +0x0008: GPIOD_PSOR — Port Set Output Register (write 1 to set pin=1)
|
|
* +0x000C: GPIOD_PCOR — Port Clear Output Register (write 1 to set pin=0)
|
|
* +0x0010: GPIOD_PTOR — Port Toggle Output Register
|
|
* +0x0014: GPIOD_PIDR — Port Input Disable Register
|
|
*
|
|
* Usage:
|
|
* gpio_devmem_init();
|
|
* gpio_devmem_set(1, 1); // GPIO1 = high
|
|
* gpio_devmem_get(4); // read GPIO4
|
|
* gpio_devmem_cleanup();
|
|
*
|
|
* Note: must run as root (CAP_SYS_RAWIO for /dev/mem access).
|
|
*/
|
|
|
|
#ifndef GPIO_DEVMEM_H
|
|
#define GPIO_DEVMEM_H
|
|
|
|
#include <stdint.h>
|
|
|
|
/*
|
|
* Initialize GPIO via /dev/mem.
|
|
* Returns: 0 on success, -1 on error.
|
|
*/
|
|
int gpio_devmem_init(void);
|
|
|
|
/*
|
|
* Cleanup /dev/mem mapping.
|
|
*/
|
|
void gpio_devmem_cleanup(void);
|
|
|
|
/*
|
|
* Set GPIO pin direction.
|
|
* gpio: 1-4 (J15 pins)
|
|
* output: 1 = output, 0 = input
|
|
* Returns: 0 on success, -1 on error.
|
|
*/
|
|
int gpio_devmem_set_direction(int gpio, int output);
|
|
|
|
/*
|
|
* Set GPIO pin: 1 = high, 0 = low.
|
|
* gpio: 1-4 (J15 pins)
|
|
* value: 0 or 1
|
|
* Returns: 0 on success, -1 on error.
|
|
*/
|
|
int gpio_devmem_set(int gpio, int value);
|
|
|
|
/*
|
|
* Get GPIO pin state: 0 = low, 1 = high.
|
|
* gpio: 1-4 (J15 pins)
|
|
* Returns: 0, 1, or -1 on error.
|
|
*/
|
|
int gpio_devmem_get(int gpio);
|
|
|
|
#endif /* GPIO_DEVMEM_H */
|