forked for MAX6951. The 3V-variant of MAX7219

Revision:
5:e1415fc2841c
Parent:
2:9150a0dc77a3
--- a/max7219.cpp	Thu May 12 20:06:28 2016 +0000
+++ b/max7219.cpp	Mon Jul 26 09:48:25 2021 +0000
@@ -39,7 +39,7 @@
 Max7219::Max7219(SPI *spi_bus, PinName cs): _p_spi(spi_bus)
 {
     _num_devices = 1;
-    
+
     _p_cs = new DigitalOut(cs, 1);
     _spi_owner = false;
 }
@@ -49,10 +49,10 @@
 Max7219::Max7219(PinName mosi, PinName miso, PinName sclk, PinName cs)
 {
     _num_devices = 1;
-    
+
     _p_spi = new SPI(mosi, miso, sclk);
     _p_cs = new DigitalOut(cs, 1);
-    
+
     _spi_owner = true;
 }
 
@@ -61,8 +61,8 @@
 Max7219::~Max7219()
 {
     delete _p_cs;
-    
-    if(_spi_owner) 
+
+    if(_spi_owner)
     {
         delete _p_spi;
     }
@@ -73,13 +73,13 @@
 int32_t Max7219::set_num_devices(uint8_t num_devices)
 {
     int32_t rtn_val = -1;
-    
+
     if(num_devices > 0)
     {
         _num_devices = num_devices;
         rtn_val = _num_devices;
     }
-    
+
     return(rtn_val);
 }
 
@@ -88,14 +88,14 @@
 void Max7219::set_display_test(void)
 {
     uint8_t idx = 0;
-    
-    _p_cs->write(0); 
+
+    _p_cs->write(0);
     for(idx = 0; idx < _num_devices; idx++)
     {
         _p_spi->write(MAX7219_DISPLAY_TEST);
         _p_spi->write(1);
     }
-    _p_cs->write(1); 
+    _p_cs->write(1);
 }
 
 
@@ -103,14 +103,14 @@
 void Max7219::clear_display_test(void)
 {
     uint8_t idx = 0;
-    
-    _p_cs->write(0); 
+
+    _p_cs->write(0);
     for(idx = 0; idx < _num_devices; idx++)
     {
         _p_spi->write(MAX7219_DISPLAY_TEST);
         _p_spi->write(0);
     }
-    _p_cs->write(1); 
+    _p_cs->write(1);
 }
 
 
@@ -119,7 +119,7 @@
 {
     int32_t rtn_val = -1;
     uint8_t idx = 0;
-    
+
     if(config.device_number > _num_devices)
     {
         rtn_val = -1;
@@ -132,7 +132,7 @@
     else
     {
         //write DECODE_MODE register of device
-        _p_cs->write(0); 
+        _p_cs->write(0);
         for(idx = _num_devices; idx > 0; idx--)
         {
             if(config.device_number == idx)
@@ -146,12 +146,12 @@
                 _p_spi->write(0);
             }
         }
-        _p_cs->write(1); 
-        
+        _p_cs->write(1);
+
         wait_us(1);
-        
+
         //write INTENSITY register of device
-        _p_cs->write(0); 
+        _p_cs->write(0);
         for(idx = _num_devices; idx > 0; idx--)
         {
             if(config.device_number == idx)
@@ -165,12 +165,12 @@
                 _p_spi->write(0);
             }
         }
-        _p_cs->write(1); 
-        
+        _p_cs->write(1);
+
         wait_us(1);
-        
+
         //write SCAN_LIMT register of device
-        _p_cs->write(0); 
+        _p_cs->write(0);
         for(idx = _num_devices; idx > 0; idx--)
         {
             if(config.device_number == idx)
@@ -184,13 +184,13 @@
                 _p_spi->write(0);
             }
         }
-        _p_cs->write(1); 
-        
+        _p_cs->write(1);
+
         wait_us(1);
-        
+
         rtn_val = 0;
     }
-    
+
     return(rtn_val);
 }
 
@@ -199,38 +199,38 @@
 void Max7219::init_display(max7219_configuration_t config)
 {
     uint8_t idx = 0;
-    
+
     //write DECODE_MODE register of all devices
-    _p_cs->write(0); 
+    _p_cs->write(0);
     for(idx = 0; idx < _num_devices; idx++)
     {
         _p_spi->write(MAX7219_DECODE_MODE);
         _p_spi->write(config.decode_mode);
     }
-    _p_cs->write(1); 
-    
+    _p_cs->write(1);
+
     wait_us(1);
-    
+
     //write INTENSITY register of all devices
-    _p_cs->write(0); 
+    _p_cs->write(0);
     for(idx = 0; idx < _num_devices; idx++)
     {
         _p_spi->write(MAX7219_INTENSITY);
         _p_spi->write(config.intensity);
     }
-    _p_cs->write(1); 
-    
+    _p_cs->write(1);
+
     wait_us(1);
-    
+
     //write SCAN_LIMT register of all devices
-    _p_cs->write(0); 
+    _p_cs->write(0);
     for(idx = 0; idx < _num_devices; idx++)
     {
         _p_spi->write(MAX7219_SCAN_LIMIT);
         _p_spi->write(config.scan_limit);
     }
-    _p_cs->write(1); 
-    
+    _p_cs->write(1);
+
     wait_us(1);
 }
 
@@ -240,7 +240,7 @@
 {
     int32_t rtn_val = -1;
     uint8_t idx = 0;
-    
+
     if(device_number > _num_devices)
     {
         rtn_val = -1;
@@ -252,12 +252,12 @@
     }
     else
     {
-        _p_cs->write(0); 
+        _p_cs->write(0);
         for(idx = _num_devices; idx > 0; idx--)
         {
             if(device_number == idx)
             {
-                _p_spi->write(MAX7219_SHUTDOWN);
+                _p_spi->write(MAX7219_CONFIGURATION);
                 _p_spi->write(1);
             }
             else
@@ -266,11 +266,11 @@
                 _p_spi->write(0);
             }
         }
-        _p_cs->write(1); 
-        
+        _p_cs->write(1);
+
         rtn_val = 0;
     }
-    
+
     return(rtn_val);
 }
 
@@ -279,23 +279,23 @@
 void Max7219::enable_display(void)
 {
     uint8_t idx = 0;
-    
-    _p_cs->write(0); 
+
+    _p_cs->write(0);
     for(idx = 0; idx < _num_devices; idx++)
     {
-        _p_spi->write(MAX7219_SHUTDOWN);
+        _p_spi->write(MAX7219_CONFIGURATION);
         _p_spi->write(1);
     }
-    _p_cs->write(1); 
+    _p_cs->write(1);
 }
-    
+
 
-//*********************************************************************    
+//*********************************************************************
 int32_t Max7219::disable_device(uint8_t device_number)
 {
     int32_t rtn_val = -1;
     uint8_t idx = 0;
-    
+
     if(device_number > _num_devices)
     {
         rtn_val = -1;
@@ -307,12 +307,12 @@
     }
     else
     {
-        _p_cs->write(0); 
+        _p_cs->write(0);
         for(idx = _num_devices; idx > 0; idx--)
         {
             if(device_number == idx)
             {
-                _p_spi->write(MAX7219_SHUTDOWN);
+                _p_spi->write(MAX7219_CONFIGURATION);
                 _p_spi->write(0);
             }
             else
@@ -321,42 +321,42 @@
                 _p_spi->write(0);
             }
         }
-        _p_cs->write(1); 
-        
+        _p_cs->write(1);
+
         rtn_val = 0;
     }
-    
+
     return(rtn_val);
 }
 
 
-//*********************************************************************    
+//*********************************************************************
 void Max7219::disable_display(void)
 {
     uint8_t idx = 0;
-    
-    _p_cs->write(0); 
+
+    _p_cs->write(0);
     for(idx = 0; idx < _num_devices; idx++)
     {
-        _p_spi->write(MAX7219_SHUTDOWN);
+        _p_spi->write(MAX7219_CONFIGURATION);
         _p_spi->write(0);
     }
-    _p_cs->write(1); 
+    _p_cs->write(1);
 }
 
 
 
-//********************************************************************* 
+//*********************************************************************
 int32_t Max7219::write_digit(uint8_t device_number, uint8_t digit, uint8_t data)
 {
     int32_t rtn_val = -1;
     uint8_t idx = 0;
-    
-    if(digit > MAX7219_DIGIT_7)
+
+    if(digit > MAX7219_D7_P0)
     {
         rtn_val = -3;
     }
-    else if(digit < MAX7219_DIGIT_0)
+    else if(digit < MAX7219_D0_P0)
     {
         rtn_val = -4;
     }
@@ -372,7 +372,7 @@
         }
         else
         {
-            _p_cs->write(0); 
+            _p_cs->write(0);
             for(idx = _num_devices; idx > 0; idx--)
             {
                 if(idx == device_number)
@@ -386,27 +386,27 @@
                     _p_spi->write(0);
                 }
             }
-            _p_cs->write(1); 
-            
+            _p_cs->write(1);
+
             rtn_val = 0;
         }
     }
-    
+
     return(rtn_val);
 }
-    
+
 
-//*********************************************************************     
+//*********************************************************************
 int32_t Max7219::clear_digit(uint8_t device_number, uint8_t digit)
 {
     int32_t rtn_val = -1;
     uint8_t idx = 0;
-    
-    if(digit > MAX7219_DIGIT_7)
+
+    if(digit > MAX7219_D7_P0)
     {
         rtn_val = -3;
     }
-    else if(digit < MAX7219_DIGIT_0)
+    else if(digit < MAX7219_D0_P0)
     {
         rtn_val = -4;
     }
@@ -422,7 +422,7 @@
         }
         else
         {
-            _p_cs->write(0); 
+            _p_cs->write(0);
             for(idx = _num_devices; idx > 0; idx--)
             {
                 if(idx == device_number)
@@ -436,22 +436,22 @@
                     _p_spi->write(0);
                 }
             }
-            _p_cs->write(1); 
-            
+            _p_cs->write(1);
+
             rtn_val = 0;
         }
     }
-    
+
     return(rtn_val);
 }
 
 
-//********************************************************************* 
+//*********************************************************************
 int32_t Max7219::device_all_on(uint8_t device_number)
 {
     int32_t rtn_val = -1;
     uint8_t idx = 0;
-    
+
     if(device_number > _num_devices)
     {
         rtn_val = -1;
@@ -463,7 +463,7 @@
     else
     {
         rtn_val = 0;
-        
+
         //writes every digit of given device to 0xFF
         for(idx = 0; idx < 8; idx++)
         {
@@ -473,17 +473,17 @@
             }
         }
     }
-    
+
     return(rtn_val);
 }
 
 
-//********************************************************************* 
+//*********************************************************************
 int32_t Max7219::device_all_off(uint8_t device_number)
 {
     int32_t rtn_val = -1;
     uint8_t idx = 0;
-    
+
     if(device_number > _num_devices)
     {
         rtn_val = -1;
@@ -495,7 +495,7 @@
     else
     {
         rtn_val = 0;
-        
+
         //writes every digit of given device to 0
         for(idx = 0; idx < 8; idx++)
         {
@@ -505,7 +505,7 @@
             }
         }
     }
-    
+
     return(rtn_val);
 }
 
@@ -513,29 +513,28 @@
 void Max7219::display_all_on(void)
 {
     uint8_t idx, idy;
-    
+
     //writes every digit of every device to 0xFF
     for(idx = 0; idx < _num_devices; idx++)
     {
-        for(idy = 0; idy < MAX7219_DIGIT_7; idy++)
+        for(idy = 0; idy < MAX7219_D7_P0; idy++)
         {
             write_digit((idx + 1), (idy + 1), 0xFF);
         }
     }
 }
-    
-    
+
+
 void Max7219::display_all_off(void)
 {
     uint8_t idx, idy;
-    
+
     //writes every digit of every device to 0
     for(idx = 0; idx < _num_devices; idx++)
     {
-        for(idy = 0; idy < MAX7219_DIGIT_7; idy++)
+        for(idy = 0; idy < MAX7219_D7_P0; idy++)
         {
             write_digit((idx + 1), (idy + 1), 0);
         }
     }
 }
-