fix: error handling, timeouts
This commit is contained in:
@ -20,17 +20,13 @@ type mt12232a struct {
|
||||
}
|
||||
|
||||
type Device interface {
|
||||
PowerOn() error
|
||||
Reset() error
|
||||
|
||||
WriteCodeL(c byte) error
|
||||
WriteCodeR(c byte) error
|
||||
WriteDataL(b byte) error
|
||||
WriteDataR(b byte) error
|
||||
WriteDatasL(b []byte) error
|
||||
WriteDatasR(b []byte) error
|
||||
WriteCode(cs rpio.State, c byte) error
|
||||
WriteData(cs rpio.State, b byte) error
|
||||
WriteDatas(cs rpio.State, b []byte) error
|
||||
|
||||
ReadDataL() (byte, error)
|
||||
ReadDataR() (byte, error)
|
||||
ReadData(cs rpio.State) (byte, error)
|
||||
ReadStatus(cs rpio.State) byte
|
||||
|
||||
io.Closer
|
||||
@ -63,6 +59,8 @@ func New(logger *log.Logger) (Device, error) {
|
||||
d.pinCS.Output()
|
||||
d.pinRES.Output()
|
||||
d.dev.Reset()
|
||||
d.pinCS.Low()
|
||||
d.pinRES.High()
|
||||
|
||||
return &d, nil
|
||||
}
|
||||
@ -72,130 +70,41 @@ func (d *mt12232a) Close() error {
|
||||
}
|
||||
|
||||
func (d *mt12232a) status() {
|
||||
d.logger.Println("STATUS:", d.ReadStatus(0)&0xF0, d.ReadStatus(1)&0xF0)
|
||||
d.logger.Printf("ST L: %08b R: %08b\n", d.ReadStatus(0)&0xFF, d.ReadStatus(1)&0xFF)
|
||||
}
|
||||
|
||||
func (d *mt12232a) PowerOn() error {
|
||||
func (d *mt12232a) Reset() error {
|
||||
d.status()
|
||||
d.logger.Println(d.ReadStatus(0)) // Should be 0
|
||||
d.logger.Println("Reset")
|
||||
d.status()
|
||||
d.pinRES.Low()
|
||||
time.Sleep(time.Microsecond)
|
||||
d.logger.Println(d.ReadStatus(0)) // Should be 48 (power off and reset)
|
||||
time.Sleep(10 * time.Microsecond)
|
||||
d.pinRES.High()
|
||||
time.Sleep(4 * time.Millisecond)
|
||||
d.logger.Println(d.ReadStatus(0)) // Should be 32 (power off)
|
||||
|
||||
// Module is reset and should be turned off
|
||||
if d.ReadStatus(0) == 0 || d.ReadStatus(1) == 0 {
|
||||
return fmt.Errorf("no response from display(or it is possible that it is turned on but...)")
|
||||
}
|
||||
for i := 0; i < 100; i++ {
|
||||
if ((d.ReadStatus(0) >> 4) & 1) == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
d.status()
|
||||
d.status()
|
||||
d.status()
|
||||
|
||||
d.logger.Println("Power on")
|
||||
d.status()
|
||||
d.WriteCodeL(0xE2) // Reset
|
||||
d.WriteCodeR(0xE2) // Reset
|
||||
d.WriteCodeL(0xEE) // ReadModifyWrite off
|
||||
d.WriteCodeR(0xEE) // ReadModifyWrite off
|
||||
d.WriteCodeL(0xA4) // Turn on common mode
|
||||
d.WriteCodeR(0xA4) // Turn on common mode
|
||||
d.WriteCodeL(0xA9) // Multiplex 1/32
|
||||
d.WriteCodeR(0xA9) // Multiplex 1/32
|
||||
d.WriteCodeL(0xC0) // Top line to 0
|
||||
d.WriteCodeR(0xC0) // Top line to 0
|
||||
d.WriteCodeL(0xA1) // Invert scan RAM
|
||||
d.WriteCodeR(0xA0) // NonInvert scan RAM
|
||||
|
||||
d.status()
|
||||
d.logger.Println("Display on")
|
||||
d.WriteCodeL(0xAF) // Display on
|
||||
d.WriteCodeR(0xAF) // Display on
|
||||
|
||||
d.status()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
d.status()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
d.status()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
d.status()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
d.status()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
d.status()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
d.status()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
d.status()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
d.status()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
d.status()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
// Check that crystals are turned on
|
||||
if ((d.ReadStatus(0) >> 5) & 1) == 1 {
|
||||
d.logger.Println("Left cristal is still off")
|
||||
}
|
||||
if ((d.ReadStatus(0) >> 5) & 1) == 1 {
|
||||
d.logger.Println("Right cristal is still off")
|
||||
}
|
||||
|
||||
// The same but with error
|
||||
if ((d.ReadStatus(0) >> 5) & 1) == 1 {
|
||||
return fmt.Errorf("Left cristal is still off")
|
||||
}
|
||||
if ((d.ReadStatus(0) >> 5) & 1) == 1 {
|
||||
return fmt.Errorf("Right cristal is still off")
|
||||
}
|
||||
time.Sleep(2 * time.Millisecond)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Write codes
|
||||
|
||||
func (d *mt12232a) WriteCodeL(c byte) error {
|
||||
return d.writeByte(c, 0, 0)
|
||||
}
|
||||
|
||||
func (d *mt12232a) WriteCodeR(c byte) error {
|
||||
return d.writeByte(c, 0, 1)
|
||||
func (d *mt12232a) WriteCode(cs rpio.State, c byte) error {
|
||||
return d.writeByte(c, 0, cs)
|
||||
}
|
||||
|
||||
// Write data as byte
|
||||
|
||||
func (d *mt12232a) WriteDataL(b byte) error {
|
||||
return d.writeByte(b, 1, 0)
|
||||
func (d *mt12232a) WriteData(cs rpio.State, b byte) error {
|
||||
return d.writeByte(b, 1, cs)
|
||||
}
|
||||
|
||||
func (d *mt12232a) WriteDataR(b byte) error {
|
||||
return d.writeByte(b, 1, 1)
|
||||
}
|
||||
|
||||
func (d *mt12232a) WriteDatasL(b []byte) error {
|
||||
return d.writeBytes(b, 1, 0)
|
||||
}
|
||||
|
||||
func (d *mt12232a) WriteDatasR(b []byte) error {
|
||||
return d.writeBytes(b, 1, 1)
|
||||
func (d *mt12232a) WriteDatas(cs rpio.State, b []byte) error {
|
||||
return d.writeBytes(b, 1, cs)
|
||||
}
|
||||
|
||||
// Read data
|
||||
|
||||
func (d *mt12232a) ReadDataL() (byte, error) {
|
||||
return d.readByte(1, 0)
|
||||
}
|
||||
|
||||
func (d *mt12232a) ReadDataR() (byte, error) {
|
||||
return d.readByte(1, 1)
|
||||
func (d *mt12232a) ReadData(cs rpio.State) (byte, error) {
|
||||
return d.readByte(1, cs)
|
||||
}
|
||||
|
||||
// Low level functions
|
||||
|
Reference in New Issue
Block a user