Skip to content

Commit

Permalink
change gpio val to data
Browse files Browse the repository at this point in the history
  • Loading branch information
amitesh-singh committed Jan 3, 2017
1 parent ceb1af8 commit 472f42d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ I shall produce an exclusive kicad schematic for this board soon.
`make hex`
`avrdude -c usbasp -p m8 -U flash:w:main.hex`

### How to compile and load driver
`cd driver/gpio`
`make`
`sudo insmod usb-gpio12.ko`

### PIN mapping

### PIN mapping
#### GPIO pins
Atmega8 gpio | pin number
-------------| ------------
PD0 | 1
Expand All @@ -40,7 +37,22 @@ PB5 | 12
PB6 | Not available (used by crystal)
PB7 | Not available (used by crystal)

### how to access gpio port
#### ADC pins
Atmega8 ADC pin | pin number
--------------- | ------------
PC0 | 0
PC1 | 1
PC2 | 2
PC3 | 3
PC4 | 4
PC5 | 5

### how to access gpio port as linux kernel sysfs
You need to load the kernel driver for this.

`$ cd driver/gpio`
`$ make`
`$ sudo insmod usb-gpio12.ko`
`$ cd /sys/class/gpio/ `
`gpiochip**N**` where **N** is the value allocated by kernel
`$ sudo chmod 666 export unexport`
Expand Down Expand Up @@ -161,10 +173,6 @@ usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
gpiopktheader *reply = (gpiopktheader *)buffer;
```
you can look into [ubstest](https://raw.githubusercontent.com/amitesh-singh/usb-gpio-board/master/firmware/usbtest/usbtest.c) example for more details.
#### example
- [on-off](https://raw.githubusercontent.com/amitesh-singh/usb-gpio-board/master/examples/on-off/on-off.c)
- SPI communication
```C
Expand Down Expand Up @@ -204,6 +212,10 @@ nBytes = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOI
buffer, 1, 1000);
```
you can look into [ubstest](https://raw.githubusercontent.com/amitesh-singh/usb-gpio-board/master/firmware/usbtest/usbtest.c) example for more details.
#### example
- [on-off](https://raw.githubusercontent.com/amitesh-singh/usb-gpio-board/master/examples/on-off/on-off.c)
### GPIO write speed
GPIO write speed is close to 1Khz.
Expand Down
30 changes: 15 additions & 15 deletions firmware/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
typedef struct __attribute__((__packed__)) _gpio_info
{
uint8_t no;
uint8_t val;
uint8_t data;
} gpio_info;

typedef struct __attribute__((__packed__)) _pktheader
typedef struct __attribute__((__packed__)) _gpiopktheader
{
uint8_t command;
gpio_info gpio;
} pktheader;
} gpiopktheader;

typedef struct __attribute__((__packed__)) _spipktheader
{
Expand All @@ -53,18 +53,18 @@ typedef struct __attribute__((__packed__)) _adcpktheader

typedef enum _command
{
BOARD_INIT,
BOARD_RESET,
GPIO_INPUT,
GPIO_OUTPUT,
GPIO_READ,
GPIO_WRITE,
SPI_INIT,
SPI_DATA,
SPI_END,
ADC_INIT,
ADC_READ,
ADC_END,
BOARD_INIT, // This does the init of board
BOARD_RESET, // This restarts the board
GPIO_INPUT, // Set GPIO as input
GPIO_OUTPUT, // Set GPIO as output
GPIO_READ, // Read GPIO
GPIO_WRITE, // Write to GPIO
SPI_INIT, // Initialize SPI
SPI_DATA, // Send data over SPI
SPI_END, // End spi connection
ADC_INIT, // Initialize ADC
ADC_READ, // Read ADC value from ADC pin (C0 - C5)
ADC_END, // End ADC
} command;


Expand Down
4 changes: 2 additions & 2 deletions firmware/usbtest/usbtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ int main(int argc, char **argv)
GPIO_READ, gpio_number, 0, buffer, 3, 5000);
printf("bytes: %d\n", nBytes);

pktheader *pkt = (pktheader *) buffer;
gpiopktheader *pkt = (gpiopktheader *) buffer;

printf("gpio value: %d\n", pkt->gpio.val);

Expand Down Expand Up @@ -321,7 +321,7 @@ int main(int argc, char **argv)
printf("ADC pin %d read value: %d\n", adc_info->gpio_no, adc_info->data);

nBytes = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
ADC_END, gpio_number | (1 << 8), 0,
ADC_END, 0, 0,
buffer, 1, 1000);
printf("adc_end: bytes: %d\n", nBytes);

Expand Down

0 comments on commit 472f42d

Please sign in to comment.