Skip to content

Instantly share code, notes, and snippets.

@piranha32
Last active December 18, 2015 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piranha32/f7cecfaaf7da8a80f5e2 to your computer and use it in GitHub Desktop.
Save piranha32/f7cecfaaf7da8a80f5e2 to your computer and use it in GitHub Desktop.
/dts-v1/;
/plugin/;
/ {
compatible = "ti,beaglebone", "ti,beaglebone-black";
/* identification */
part-number = "tlc5946_gpio_pins";
fragment@0 {
target = <&am33xx_pinmux>;
__overlay__ {
pinctrl_tlc5946: pinctrl_tlc5946_pins {
pinctrl-single,pins = <
0x074 0x37 /* xerr: P9_13 = uart4_txd, INPUT_PULLUP | MODE7 */
0x040 0x17 /* mode: P9_15 = gpio1_16, OUTPUT_PULLUP | MODE7 */
0x04c 0x17 /* blank: P9_16 = ehrpwm1b, OUTPUT_PULLUP | MODE7 */
0x044 0x17 /* xhalf: P9_23 = gpio1_17, OUTPUT_PULLUP | MODE7 */
>;
};
};
};
fragment@1 {
target = <&ocp>;
__overlay__ {
#address-cells = <1>;
#size-cells = <1>;
tlc_gpios {
compatible = "bone-pinmux-helper";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_tlc5946>;
status = "okay";
};
};
};
};
#include <stdio.h>
#include <fcntl.h>
#include <sys/mman.h>
#define DATA_OUT_REG 0x13C
static void test_gpio()
{
int gpio_fd = open("/dev/mem", O_RDWR | O_SYNC);
if (gpio_fd < 0)
{
printf("Cannot open /dev/mem\n");
return;
}
unsigned long *gpio = (unsigned long *) mmap(NULL, 0xFFF,
PROT_READ | PROT_WRITE, MAP_SHARED, gpio_fd, 0x4804C000);
if (gpio <= 0)
{
printf("GPIO Mapping failed\n");
return;
}
unsigned int i=0;
for(;;)
{
printf("Loop %i, setting 0\n",i);
gpio[DATA_OUT_REG / 4]=0;
sleep(1);
printf("Loop %i, setting 1\n",i);
gpio[DATA_OUT_REG / 4]=0xffffffff;
sleep(1);
i++;
}
}
int main()
{
test_gpio();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment