Add: beta working mt12232a display
This commit is contained in:
@ -21,12 +21,13 @@ type mt12232a struct {
|
||||
|
||||
type Device interface {
|
||||
PowerOn() error
|
||||
SetPixel(x, y byte, c bool) 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
|
||||
|
||||
ReadDataL() (byte, error)
|
||||
ReadDataR() (byte, error)
|
||||
@ -42,23 +43,22 @@ func New(logger *log.Logger) (Device, error) {
|
||||
logger: logger,
|
||||
|
||||
dev: parallel8bit.New(logger, parallel8bit.DevicePins{
|
||||
PinA0: rpio.Pin(18),
|
||||
PinRW: rpio.Pin(17),
|
||||
PinE: rpio.Pin(27),
|
||||
PinA0: rpio.Pin(19),
|
||||
PinRW: rpio.Pin(13),
|
||||
PinE: rpio.Pin(12),
|
||||
|
||||
PinDB0: rpio.Pin(22),
|
||||
PinDB1: rpio.Pin(10),
|
||||
PinDB2: rpio.Pin(9), // From 21
|
||||
PinDB2: rpio.Pin(9),
|
||||
PinDB3: rpio.Pin(11),
|
||||
PinDB4: rpio.Pin(12),
|
||||
PinDB5: rpio.Pin(16), // From 32
|
||||
PinDB6: rpio.Pin(20), // From 31
|
||||
PinDB7: rpio.Pin(13), // From 33
|
||||
|
||||
PinDB4: rpio.Pin(21),
|
||||
PinDB5: rpio.Pin(20),
|
||||
PinDB6: rpio.Pin(26),
|
||||
PinDB7: rpio.Pin(16),
|
||||
}),
|
||||
|
||||
pinCS: rpio.Pin(19),
|
||||
pinRES: rpio.Pin(21),
|
||||
pinCS: rpio.Pin(17),
|
||||
pinRES: rpio.Pin(27),
|
||||
}
|
||||
d.pinCS.Output()
|
||||
d.pinRES.Output()
|
||||
@ -71,47 +71,37 @@ func (d *mt12232a) Close() error {
|
||||
return rpio.Close()
|
||||
}
|
||||
|
||||
func (d *mt12232a) SetPixel(x, y byte, c bool) error {
|
||||
// var c8 byte
|
||||
// var mask byte
|
||||
|
||||
// Check bounds
|
||||
if x > 127 || y > 63 {
|
||||
return fmt.Errorf("positions out of bounds")
|
||||
}
|
||||
|
||||
if x < 64 { // Left crystal
|
||||
d.WriteCodeL(0xB8 | (y >> 3)) // Set page
|
||||
d.WriteCodeL(0x40 | x) // Set addr
|
||||
// c8=ReadDataL(); // ?? ok
|
||||
// c8=ReadDataL(); // Read byte
|
||||
// m8=1<<(y&0x07);//Вычислить маску нужного бита в байте
|
||||
// if (c==1) //Зажигать точку?
|
||||
// c8|=m8//Установить нужный бит в байте
|
||||
// else //Или гасить точку?
|
||||
// c8&=~m8;//Сбросить нужный бит в байте
|
||||
// WriteCodeL(0x40|x);//Снова установить адрес нужного байта
|
||||
d.WriteDataL(0x34) // Write byte
|
||||
}
|
||||
return nil
|
||||
func (d *mt12232a) status() {
|
||||
d.logger.Println("STATUS:", d.ReadStatus(0)&0xF0, d.ReadStatus(1)&0xF0)
|
||||
}
|
||||
|
||||
func (d *mt12232a) PowerOn() 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)
|
||||
d.pinRES.High()
|
||||
time.Sleep(10 * time.Microsecond)
|
||||
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
|
||||
@ -125,15 +115,45 @@ func (d *mt12232a) PowerOn() error {
|
||||
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) & (1 << 5)) != 0 {
|
||||
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(1) & (1 << 5)) != 0 {
|
||||
if ((d.ReadStatus(0) >> 5) & 1) == 1 {
|
||||
return fmt.Errorf("Right cristal is still off")
|
||||
}
|
||||
|
||||
@ -160,6 +180,14 @@ 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)
|
||||
}
|
||||
|
||||
// Read data
|
||||
|
||||
func (d *mt12232a) ReadDataL() (byte, error) {
|
||||
@ -173,7 +201,6 @@ func (d *mt12232a) ReadDataR() (byte, error) {
|
||||
// Low level functions
|
||||
|
||||
func (d *mt12232a) writeByte(b byte, cd, cs rpio.State) error {
|
||||
// d.logger.Println("Write byte", b, cd, l, r)
|
||||
if err := d.waitReady(cs); err != nil {
|
||||
return fmt.Errorf("wait ready: %w", err)
|
||||
}
|
||||
@ -183,6 +210,16 @@ func (d *mt12232a) writeByte(b byte, cd, cs rpio.State) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *mt12232a) writeBytes(b []byte, cd, cs rpio.State) error {
|
||||
if err := d.waitReady(cs); err != nil {
|
||||
return fmt.Errorf("wait ready: %w", err)
|
||||
}
|
||||
d.pinCS.Write(cs) // Select cristals
|
||||
|
||||
d.dev.WriteBytes(b, cd)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *mt12232a) readByte(cd, cs rpio.State) (byte, error) {
|
||||
// Setup
|
||||
if err := d.waitReady(cs); err != nil {
|
||||
|
Reference in New Issue
Block a user