예제 #1
0
파일: ATC2603C.go 프로젝트: tjCFeng/GoS500
func IATC2603C() *ATC2603C {
	if iATC2603C == nil {
		iATC2603C = &ATC2603C{}

		iATC2603C.twi, _ = S500.CreateTWI(nil, nil, S500.TWI_0)
		iATC2603C.twi.SetSpeed(S500.TWI_SpeedLow)
	}

	return iATC2603C
}
예제 #2
0
파일: DS3231.go 프로젝트: tjCFeng/GoS500
func IDS3231() (*DS3231) {
	if (iDS3231 == nil) {
		iDS3231 = &DS3231{}
		iDS3231.sda, _ = S500.CreateGPIO(S500.PE, 3)
		iDS3231.scl, _ = S500.CreateGPIO(S500.PE, 2)
		iDS3231.twi, _ = S500.CreateTWI(iDS3231.sda, iDS3231.scl, S500.TWI_2)
		iDS3231.twi.SetSpeed(S500.TWI_SpeedLow)
	}

	return iDS3231
}
예제 #3
0
파일: GoS500.go 프로젝트: tjCFeng/GoS500
func main() {
	defer S500.FreeS500()

	/*GPIO*/
	//echo "none" > /sys/class/leds/green:GPIOB12/trigger
	PB12, _ := S500.CreateGPIO(S500.PB, 12)
	defer S500.FreeGPIO(PB12)
	PB12.SetFun(S500.FunOUT)
	PB12.Flip()

	//echo "none" > /sys/class/leds/blue:GPIOB31/trigger
	PB31, _ := S500.CreateGPIO(S500.PB, 31)
	defer S500.FreeGPIO(PB31)
	PB31.SetFun(S500.FunOUT)
	PB31.Flip()

	/*PWM*/
	PB31, _ := S500.CreateGPIO(S500.PB, 31)
	PWM3, _ := S500.CreatePWM(PB31, S500.PWM_3)
	defer S500.FreePWM(PWM3)
	PWM3.SetSRC(S500.PWM_HOSC_24M)
	PWM3.SetDIV(0xFF)
	PWM3.SetPolarity(true)
	PWM3.SetPeriod(1000)
	PWM3.SetDuty(500)

	/*SPI*/
	Device.ISSD1306().Open()
	defer Device.FreeSSD1306()
	Device.ISSD1306().Writes(0, 0, []uint8("LeMaker Guitar"))
	Device.ISSD1306().Writes(0, 1, []uint8(" -- www.ICKey.cn"))

	/*TWI*/
	SDA, _ := S500.CreateGPIO(S500.PE, 3)
	SCL, _ := S500.CreateGPIO(S500.PE, 2)
	TWI2, _ := S500.CreateTWI(SDA, SCL, S500.TWI_2)
	defer S500.FreeTWI(TWI2)
	TWI2.SetSpeed(S500.TWI_SpeedLow)

	HMC5883ADDR := uint8(0x1E)
	TWI2.Write(HMC5883ADDR, 0x00, []uint8{0x14})
	TWI2.Write(HMC5883ADDR, 0x01, []uint8{0x20})
	TWI2.Write(HMC5883ADDR, 0x02, []uint8{0x00})

	go func() {
		for {
			Data, ok := TWI2.Read(HMC5883ADDR, 0x03, 6)
			fmt.Println(Data, ok)
			time.Sleep(1 * time.Second)
		}
	}()

	//fmt.Println(Device.IDS3231().Write(16, 2, 11, 20, 24, 30, 4))
	fmt.Println(Device.IDS3231().Read())
	fmt.Println(Device.IDS3231().Temperature())

	/*ATC2603C*/
	fmt.Println("Ver:", Device.IATC2603C().Version())
	fmt.Println("Temperature:", Device.IATC2603C().Temperature(), "C")
	fmt.Println("SYSPWR:", Device.IATC2603C().VoltageMV(Device.V_SYSPWR), "mV")
	fmt.Println("WALL:", Device.IATC2603C().CurrentMA(Device.A_WALL), "mA")
	Data := Device.IATC2603C().ADC(0)
	fmt.Println("ADC Data:", Data)
	fmt.Println("ADC0:", Device.IATC2603C().ConvertADCmV(Data), "mV")
	defer Device.FreeATC2603C()

	reader := bufio.NewReader(os.Stdin)
	for {
		key, _, _ := reader.ReadLine()
		switch string(key) {
		case "exit":
			return
		default:
			continue
		}
	}
}