Пример #1
0
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
}
Пример #2
0
func ISSD1306() *SSD1306 {
	if iSSD1306 == nil {
		iSSD1306 = &SSD1306{}

		iSSD1306.mosi, _ = S500.CreateGPIO(S500.PC, 25)
		iSSD1306.miso, _ = S500.CreateGPIO(S500.PC, 24)
		iSSD1306.sclk, _ = S500.CreateGPIO(S500.PC, 22)
		iSSD1306.cs, _ = S500.CreateGPIO(S500.PC, 23)
		iSSD1306.spi, _ = S500.CreateSPI(iSSD1306.mosi, iSSD1306.miso, iSSD1306.sclk, iSSD1306.cs, S500.SPI_0)
		iSSD1306.spi.SetDIV(0x3FF)
		iSSD1306.spi.Open()

		iSSD1306.dc, _ = S500.CreateGPIO(S500.PC, 6)
		iSSD1306.dc.SetFun(S500.FunOUT)
		iSSD1306.rst, _ = S500.CreateGPIO(S500.PC, 5)
		iSSD1306.rst.SetFun(S500.FunOUT)

		iSSD1306.ssd1306_init()
	}

	return iSSD1306
}
Пример #3
0
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
		}
	}
}