1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-08 19:29:16 +08:00

chip: add preliminary support for C.H.I.P. Pro

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2017-04-22 13:34:19 +02:00
parent 1aff614827
commit 8cfb7db7cd
5 changed files with 232 additions and 12 deletions

View File

@ -4,6 +4,9 @@ The [C.H.I.P.](http://www.getchip.com/) is a small, inexpensive ARM based single
For documentation about the C.H.I.P. platform click [here](http://docs.getchip.com/).
The [C.H.I.P. Pro](https://getchip.com/pages/chippro) is a version of C.H.I.P. intended for use in embedded product development. Here is info about the [C.H.I.P. Pro pin headers](https://docs.getchip.com/chip_pro.html#pin-descriptions).
## How to Install
We recommend updating to the latest Debian OS when using the C.H.I.P., however Gobot should also support older versions of the OS, should your application require this.
@ -71,6 +74,13 @@ func main() {
}
```
If you want to use the C.H.I.P. Pro, use the `SetBoard()` function like this:
```go
chipProAdaptor := chip.NewAdaptor()
chipProAdaptor.SetBoard("CHIP Pro")
```
## How to Connect
### Compiling

View File

@ -22,16 +22,18 @@ type sysfsPin struct {
// Adaptor represents a Gobot Adaptor for a C.H.I.P.
type Adaptor struct {
name string
digitalPins map[int]sysfs.DigitalPin
board string
pinmap map[string]sysfsPin
i2cBuses [3]sysfs.I2cDevice
digitalPins map[int]sysfs.DigitalPin
pwmPins map[int]*sysfs.PWMPin
i2cBuses [3]sysfs.I2cDevice
}
// NewAdaptor creates a C.H.I.P. Adaptor
func NewAdaptor() *Adaptor {
c := &Adaptor{
name: gobot.DefaultName("CHIP"),
board: "CHIP",
digitalPins: make(map[int]sysfs.DigitalPin),
}
@ -158,6 +160,30 @@ func (c *Adaptor) ServoWrite(pin string, angle byte) (err error) {
return pwmPin.SetDutyCycle(duty)
}
// SetBoard sets the name of the type of board
func (c *Adaptor) SetBoard(n string) (err error) {
if n == "CHIP Pro" || n == "CHIP" {
c.board = n
c.setPins()
return
}
return errors.New("Invalid board type")
}
func (c *Adaptor) setPins() {
if c.board == "CHIP Pro" {
c.pinmap = chipProPins
return
}
// otherwise, original CHIP
c.pinmap = chipPins
baseAddr, _ := getXIOBase()
for i := 0; i < 8; i++ {
pin := fmt.Sprintf("XIO-P%d", i)
c.pinmap[pin] = sysfsPin{pin: baseAddr + i, pwmPin: -1}
}
}
func getXIOBase() (baseAddr int, err error) {
// Default to original base from 4.3 kernel
baseAddr = 408
@ -188,15 +214,6 @@ func getXIOBase() (baseAddr int, err error) {
return baseAddr, nil
}
func (c *Adaptor) setPins() {
c.pinmap = fixedPins
baseAddr, _ := getXIOBase()
for i := 0; i < 8; i++ {
pin := fmt.Sprintf("XIO-P%d", i)
c.pinmap[pin] = sysfsPin{pin: baseAddr + i, pwmPin: -1}
}
}
func (c *Adaptor) translatePin(pin string) (i int, err error) {
if val, ok := c.pinmap[pin]; ok {
i = val.pin

View File

@ -57,6 +57,31 @@ func TestChipAdaptorDigitalIO(t *testing.T) {
gobottest.Assert(t, a.Finalize(), nil)
}
func TestChipProAdaptorDigitalIO(t *testing.T) {
a := initTestChipAdaptor()
a.SetBoard("CHIP Pro")
fs := sysfs.NewMockFilesystem([]string{
"/sys/class/gpio/export",
"/sys/class/gpio/unexport",
"/sys/class/gpio/gpio50/value",
"/sys/class/gpio/gpio50/direction",
"/sys/class/gpio/gpio139/value",
"/sys/class/gpio/gpio139/direction",
})
sysfs.SetFilesystem(fs)
a.DigitalWrite("CSID7", 1)
gobottest.Assert(t, fs.Files["/sys/class/gpio/gpio139/value"].Contents, "1")
fs.Files["/sys/class/gpio/gpio50/value"].Contents = "1"
i, _ := a.DigitalRead("TWI2-SDA")
gobottest.Assert(t, i, 1)
gobottest.Assert(t, a.DigitalWrite("XIO-P0", 1), errors.New("Not a valid pin"))
gobottest.Assert(t, a.Finalize(), nil)
}
func TestChipAdaptorI2c(t *testing.T) {
a := initTestChipAdaptor()
fs := sysfs.NewMockFilesystem([]string{

View File

@ -1,6 +1,6 @@
package chip
var fixedPins = map[string]sysfsPin{
var chipPins = map[string]sysfsPin{
"PWM0": {
pin: 34,
pwmPin: 0,

View File

@ -0,0 +1,168 @@
package chip
var chipProPins = map[string]sysfsPin{
"PWM0": {
pin: 34,
pwmPin: 0,
},
"PWM1": {
pin: 205,
pwmPin: 1,
},
"LCD-D2": {
pin: 98,
pwmPin: -1,
},
"LCD-D3": {
pin: 99,
pwmPin: -1,
},
"LCD-D4": {
pin: 100,
pwmPin: -1,
},
"LCD-D5": {
pin: 101,
pwmPin: -1,
},
"LCD-D6": {
pin: 102,
pwmPin: -1,
},
"LCD-D7": {
pin: 103,
pwmPin: -1,
},
"LCD-D10": {
pin: 106,
pwmPin: -1,
},
"LCD-D11": {
pin: 107,
pwmPin: -1,
},
"LCD-D12": {
pin: 108,
pwmPin: -1,
},
"LCD-D13": {
pin: 109,
pwmPin: -1,
},
"LCD-D14": {
pin: 110,
pwmPin: -1,
},
"LCD-D15": {
pin: 111,
pwmPin: -1,
},
"LCD-D18": {
pin: 114,
pwmPin: -1,
},
"LCD-D19": {
pin: 115,
pwmPin: -1,
},
"LCD-D20": {
pin: 116,
pwmPin: -1,
},
"LCD-D21": {
pin: 117,
pwmPin: -1,
},
"LCD-D22": {
pin: 118,
pwmPin: -1,
},
"LCD-D23": {
pin: 119,
pwmPin: -1,
},
"LCD-CLK": {
pin: 120,
pwmPin: -1,
},
"LCD-HSYNC": {
pin: 122,
pwmPin: -1,
},
"LCD-VSYNC": {
pin: 123,
pwmPin: -1,
},
"UART1-TX": {
pin: 195,
pwmPin: -1,
},
"UART1-RX": {
pin: 196,
pwmPin: -1,
},
"AP-EINT1": {
pin: 193,
pwmPin: -1,
},
"AP-EINT3": {
pin: 35,
pwmPin: -1,
},
"TWI2-SCK": {
pin: 49,
pwmPin: -1,
},
"TWI2-SDA": {
pin: 50,
pwmPin: -1,
},
"CSIPCK": {
pin: 128,
pwmPin: -1,
},
"CSICK": {
pin: 129,
pwmPin: -1,
},
"CSIHSYNC": {
pin: 130,
pwmPin: -1,
},
"CSIVSYNC": {
pin: 131,
pwmPin: -1,
},
"CSID0": {
pin: 132,
pwmPin: -1,
},
"CSID1": {
pin: 133,
pwmPin: -1,
},
"CSID2": {
pin: 134,
pwmPin: -1,
},
"CSID3": {
pin: 135,
pwmPin: -1,
},
"CSID4": {
pin: 136,
pwmPin: -1,
},
"CSID5": {
pin: 137,
pwmPin: -1,
},
"CSID6": {
pin: 138,
pwmPin: -1,
},
"CSID7": {
pin: 139,
pwmPin: -1,
},
}