2424#include <linux/workqueue.h>
2525#include "tinker_mcu.h"
2626
27+ #define BL_DEBUG 0
2728static struct tinker_mcu_data * g_mcu_data ;
2829static int connected = 0 ;
30+ static int lcd_bright_level = 0 ;
2931
3032static int is_hex (char num )
3133{
@@ -147,7 +149,7 @@ int tinker_mcu_set_bright(int bright)
147149 if (bright > 0xff || bright < 0 )
148150 return - EINVAL ;
149151
150- LOG_INFO ("bright = 0x%x\n" , bright );
152+ if ( BL_DEBUG ) LOG_INFO ("set bright = 0x%x\n" , bright );
151153
152154 cmd [0 ] = 0x86 ;
153155 cmd [1 ] = bright ;
@@ -158,10 +160,34 @@ int tinker_mcu_set_bright(int bright)
158160 return ret != 0 ? ret : - ECOMM ;
159161 }
160162
163+ lcd_bright_level = bright ;
164+
161165 return 0 ;
162166}
163167EXPORT_SYMBOL_GPL (tinker_mcu_set_bright );
164168
169+ static ssize_t tinker_mcu_bl_show (struct device * dev , struct device_attribute * attr , char * buf )
170+ {
171+ if (BL_DEBUG ) LOG_INFO ("get bright = 0x%x\n" , lcd_bright_level );
172+
173+ return sprintf (buf , "%d\n" , lcd_bright_level );
174+ }
175+
176+ static ssize_t tinker_mcu_bl_store (struct device * dev , struct device_attribute * attr , const char * buf , size_t count )
177+ {
178+ int value ;
179+
180+ value = simple_strtoul (buf , NULL , 0 );
181+
182+ if ((value < 0 ) || (value > 255 )) {
183+ LOG_ERR ("Invalid value for backlight setting, value = %d\n" , value );
184+ } else
185+ tinker_mcu_set_bright (value );
186+
187+ return strnlen (buf , count );
188+ }
189+ static DEVICE_ATTR (tinker_mcu_bl , S_IRUGO | S_IWUSR , tinker_mcu_bl_show , tinker_mcu_bl_store ) ;
190+
165191int tinker_mcu_is_connected (void )
166192{
167193 return connected ;
@@ -198,6 +224,12 @@ static int tinker_mcu_probe(struct i2c_client *client,
198224 }
199225 connected = 1 ;
200226
227+ ret = device_create_file (& client -> dev , & dev_attr_tinker_mcu_bl );
228+ if (ret != 0 ) {
229+ dev_err (& client -> dev , "Failed to create tinker_mcu_bl sysfs files %d\n" , ret );
230+ return ret ;
231+ }
232+
201233 return 0 ;
202234
203235error :
0 commit comments