mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-06 07:53:41 +00:00
30 lines
567 B
Go
30 lines
567 B
Go
//go:build !thumby
|
|
|
|
package main
|
|
|
|
import (
|
|
"machine"
|
|
|
|
"tinygo.org/x/drivers/ssd1306"
|
|
)
|
|
|
|
func makeSSD1306(width, height int16) (*ssd1306.Device, error) {
|
|
err := machine.I2C0.Configure(machine.I2CConfig{
|
|
Frequency: 400 * machine.KHz,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
address := uint16(ssd1306.Address)
|
|
if width == 128 && (height == 32 || height == 64) {
|
|
address = ssd1306.Address_128_32
|
|
}
|
|
display := ssd1306.NewI2C(machine.I2C0)
|
|
display.Configure(ssd1306.Config{
|
|
Address: address,
|
|
Width: width,
|
|
Height: height,
|
|
})
|
|
return &display, nil
|
|
}
|