Skip to content

Commit 692f71a

Browse files
committed
docs: modify some content
1 parent 42c4a35 commit 692f71a

File tree

8 files changed

+213
-69
lines changed

8 files changed

+213
-69
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ LibDriver AT24CXX is the full function driver of AT24CXX launched by LibDriver.
3939

4040
/project includes the common Linux and MCU development board sample code. All projects use the shell script to debug the driver and the detail instruction can be found in each project's README.md.
4141

42+
/misra includes the LibDriver MISRA code scanning results.
43+
4244
### Install
4345

4446
Reference /interface IIC platform independent template and finish your platform IIC driver.

README_de.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ LibDriver AT24CXX ist der Treiber mit vollem Funktionsumfang von AT24CXX, der vo
3838

3939
/project enthält den allgemeinen Beispielcode für Linux- und MCU-Entwicklungsboards. Alle Projekte verwenden das Shell-Skript, um den Treiber zu debuggen, und die detaillierten Anweisungen finden Sie in der README.md jedes Projekts.
4040

41+
/misra enthält die Ergebnisse des LibDriver MISRA Code Scans.
42+
4143
### Installieren
4244

4345
Verweisen Sie auf eine plattformunabhängige IIC-Schnittstellenvorlage und stellen Sie Ihren Plattform-IIC-Treiber fertig.

README_ja.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ LibDriver AT24CXXは、LibDriverによって起動されたAT24CXXの全機能
3939

4040
/ projectディレクトリには、一般的に使用されるLinuxおよびマイクロコントローラー開発ボードのプロジェクトサンプルが含まれています。 すべてのプロジェクトは、デバッグ方法としてシェルスクリプトを使用しています。詳細については、各プロジェクトのREADME.mdを参照してください。
4141

42+
/ misraはLibDriver misraコードスキャン結果を含む。
43+
4244
### インストール
4345

4446
/ interfaceディレクトリにあるプラットフォームに依存しないIICバステンプレートを参照して、指定したプラットフォームのIICバスドライバを完成させます。

README_ko.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ LibDriver AT24CXX는 LibDriver에서 출시한 AT24CXX의 전체 기능 드라
3939

4040
/project 디렉토리에는 일반적으로 사용되는 Linux 및 마이크로컨트롤러 개발 보드의 프로젝트 샘플이 포함되어 있습니다. 모든 프로젝트는 디버깅 방법으로 셸 스크립트를 사용하며, 자세한 내용은 각 프로젝트의 README.md를 참조하십시오.
4141

42+
/misra 에는 LibDriver misra 코드 검색 결과가 포함됩니다.
43+
4244
### 설치
4345

4446
/interface 디렉토리에서 플랫폼 독립적인 IIC버스 템플릿을 참조하여 지정된 플랫폼에 대한 IIC버스 드라이버를 완성하십시오.

README_zh-Hans.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ LibDriver AT24CXX是LibDriver推出的AT24CXX的全功能驱动,该驱动提
3939

4040
/project目录包含了常用Linux与单片机开发板的工程样例。所有工程均采用shell脚本作为调试方法,详细内容可参考每个工程里面的README.md。
4141

42+
/misra目录包含了LibDriver MISRA代码扫描结果。
43+
4244
### 安装
4345

4446
参考/interface目录下与平台无关的IIC总线模板,完成指定平台的IIC总线驱动。

README_zh-Hant.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ LibDriver AT24CXX是LibDriver推出的AT24CXX的全功能驅動,該驅動提
3939

4040
/project目錄包含了常用Linux與單片機開發板的工程樣例。所有工程均採用shell腳本作為調試方法,詳細內容可參考每個工程裡面的README.md。
4141

42+
/misra目錄包含了LibDriver MISRA程式碼掃描結果。
43+
4244
### 安裝
4345

4446
參考/interface目錄下與平台無關的IIC總線模板,完成指定平台的IIC總線驅動。

project/raspberrypi4b/src/main.c

Lines changed: 100 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "driver_at24cxx_read_test.h"
3838
#include "driver_at24cxx_basic.h"
3939
#include <getopt.h>
40+
#include <math.h>
4041
#include <stdlib.h>
4142

4243
/**
@@ -189,63 +190,128 @@ uint8_t at24cxx(uint8_t argc, char **argv)
189190
/* data */
190191
case 2 :
191192
{
193+
char *p;
194+
uint16_t l;
195+
uint16_t i;
196+
uint64_t hex_data;
197+
192198
/* set the data */
193-
if ((optarg[0] <= '9') && (optarg[0] >= '0'))
199+
l = strlen(optarg);
200+
201+
/* check the header */
202+
if (l >= 2)
194203
{
195-
data = (optarg[0] - '0') * 16;
204+
if (strncmp(optarg, "0x", 2) == 0)
205+
{
206+
p = optarg + 2;
207+
l -= 2;
208+
}
209+
else if (strncmp(optarg, "0X", 2) == 0)
210+
{
211+
p = optarg + 2;
212+
l -= 2;
213+
}
214+
else
215+
{
216+
p = optarg;
217+
}
196218
}
197219
else
198220
{
199-
data = (optarg[0] - 'A' + 10) * 16;
200-
}
201-
if ((optarg[1] <= '9') && (optarg[1] >= '0'))
202-
{
203-
data += (optarg[1] - '0');
221+
p = optarg;
204222
}
205-
else
223+
224+
/* init 0 */
225+
hex_data = 0;
226+
227+
/* loop */
228+
for (i = 0; i < l; i++)
206229
{
207-
data += (optarg[1] - 'A' + 10);
230+
if ((p[i] <= '9') && (p[i] >= '0'))
231+
{
232+
hex_data += (p[i] - '0') * (uint32_t)pow(16, l - i - 1);
233+
}
234+
else if ((p[i] <= 'F') && (p[i] >= 'A'))
235+
{
236+
hex_data += ((p[i] - 'A') + 10) * (uint32_t)pow(16, l - i - 1);
237+
}
238+
else if ((p[i] <= 'f') && (p[i] >= 'a'))
239+
{
240+
hex_data += ((p[i] - 'a') + 10) * (uint32_t)pow(16, l - i - 1);
241+
}
242+
else
243+
{
244+
return 5;
245+
}
208246
}
209247

248+
/* set the data */
249+
data = hex_data & 0xFF;
250+
210251
break;
211252
}
212253

213254
/* register */
214255
case 3 :
215256
{
216-
if ((optarg[0] <= '9') && (optarg[0] >= '0'))
217-
{
218-
reg = (optarg[0] - '0') * 16 * 16 *16;
219-
}
220-
else
221-
{
222-
reg = (optarg[0] - 'A' + 10) * 16 * 16 *16;
223-
}
224-
if ((optarg[1] <= '9') && (optarg[1] >= '0'))
225-
{
226-
reg += (optarg[1] - '0') * 16 * 16;
227-
}
228-
else
229-
{
230-
reg += (optarg[1] - 'A' + 10) * 16 * 16;
231-
}
232-
if ((optarg[2] <= '9') && (optarg[2] >= '0'))
257+
char *p;
258+
uint16_t l;
259+
uint16_t i;
260+
uint64_t hex_data;
261+
262+
/* set the data */
263+
l = strlen(optarg);
264+
265+
/* check the header */
266+
if (l >= 2)
233267
{
234-
reg += (optarg[2] - '0') * 16;
268+
if (strncmp(optarg, "0x", 2) == 0)
269+
{
270+
p = optarg + 2;
271+
l -= 2;
272+
}
273+
else if (strncmp(optarg, "0X", 2) == 0)
274+
{
275+
p = optarg + 2;
276+
l -= 2;
277+
}
278+
else
279+
{
280+
p = optarg;
281+
}
235282
}
236283
else
237284
{
238-
reg += (optarg[2] - 'A' + 10) * 16;
285+
p = optarg;
239286
}
240-
if ((optarg[3] <= '9') && (optarg[3] >= '0'))
241-
{
242-
reg += (optarg[3] - '0');
243-
}
244-
else
287+
288+
/* init 0 */
289+
hex_data = 0;
290+
291+
/* loop */
292+
for (i = 0; i < l; i++)
245293
{
246-
reg += (optarg[3] - 'A' + 10);
294+
if ((p[i] <= '9') && (p[i] >= '0'))
295+
{
296+
hex_data += (p[i] - '0') * (uint32_t)pow(16, l - i - 1);
297+
}
298+
else if ((p[i] <= 'F') && (p[i] >= 'A'))
299+
{
300+
hex_data += ((p[i] - 'A') + 10) * (uint32_t)pow(16, l - i - 1);
301+
}
302+
else if ((p[i] <= 'f') && (p[i] >= 'a'))
303+
{
304+
hex_data += ((p[i] - 'a') + 10) * (uint32_t)pow(16, l - i - 1);
305+
}
306+
else
307+
{
308+
return 5;
309+
}
247310
}
248311

312+
/* set the data */
313+
reg = hex_data & 0xFFFF;
314+
249315
break;
250316
}
251317

project/stm32f407/usr/src/main.c

Lines changed: 101 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "delay.h"
4242
#include "uart.h"
4343
#include "getopt.h"
44+
#include <math.h>
4445
#include <stdlib.h>
4546

4647
/**
@@ -199,62 +200,127 @@ uint8_t at24cxx(uint8_t argc, char **argv)
199200
/* data */
200201
case 2 :
201202
{
203+
char *p;
204+
uint16_t l;
205+
uint16_t i;
206+
uint64_t hex_data;
207+
202208
/* set the data */
203-
if ((optarg[0] <= '9') && (optarg[0] >= '0'))
209+
l = strlen(optarg);
210+
211+
/* check the header */
212+
if (l >= 2)
204213
{
205-
data = (optarg[0] - '0') * 16;
214+
if (strncmp(optarg, "0x", 2) == 0)
215+
{
216+
p = optarg + 2;
217+
l -= 2;
218+
}
219+
else if (strncmp(optarg, "0X", 2) == 0)
220+
{
221+
p = optarg + 2;
222+
l -= 2;
223+
}
224+
else
225+
{
226+
p = optarg;
227+
}
206228
}
207229
else
208230
{
209-
data = (optarg[0] - 'A' + 10) * 16;
210-
}
211-
if ((optarg[1] <= '9') && (optarg[1] >= '0'))
212-
{
213-
data += (optarg[1] - '0');
231+
p = optarg;
214232
}
215-
else
233+
234+
/* init 0 */
235+
hex_data = 0;
236+
237+
/* loop */
238+
for (i = 0; i < l; i++)
216239
{
217-
data += (optarg[1] - 'A' + 10);
240+
if ((p[i] <= '9') && (p[i] >= '0'))
241+
{
242+
hex_data += (p[i] - '0') * (uint32_t)pow(16, l - i - 1);
243+
}
244+
else if ((p[i] <= 'F') && (p[i] >= 'A'))
245+
{
246+
hex_data += ((p[i] - 'A') + 10) * (uint32_t)pow(16, l - i - 1);
247+
}
248+
else if ((p[i] <= 'f') && (p[i] >= 'a'))
249+
{
250+
hex_data += ((p[i] - 'a') + 10) * (uint32_t)pow(16, l - i - 1);
251+
}
252+
else
253+
{
254+
return 5;
255+
}
218256
}
219-
257+
258+
/* set the data */
259+
data = hex_data & 0xFF;
260+
220261
break;
221262
}
222263

223264
/* register */
224265
case 3 :
225266
{
226-
if ((optarg[0] <= '9') && (optarg[0] >= '0'))
227-
{
228-
reg = (optarg[0] - '0') * 16 * 16 *16;
229-
}
230-
else
231-
{
232-
reg = (optarg[0] - 'A' + 10) * 16 * 16 *16;
233-
}
234-
if ((optarg[1] <= '9') && (optarg[1] >= '0'))
235-
{
236-
reg += (optarg[1] - '0') * 16 * 16;
237-
}
238-
else
239-
{
240-
reg += (optarg[1] - 'A' + 10) * 16 * 16;
241-
}
242-
if ((optarg[2] <= '9') && (optarg[2] >= '0'))
267+
char *p;
268+
uint16_t l;
269+
uint16_t i;
270+
uint64_t hex_data;
271+
272+
/* set the data */
273+
l = strlen(optarg);
274+
275+
/* check the header */
276+
if (l >= 2)
243277
{
244-
reg += (optarg[2] - '0') * 16;
278+
if (strncmp(optarg, "0x", 2) == 0)
279+
{
280+
p = optarg + 2;
281+
l -= 2;
282+
}
283+
else if (strncmp(optarg, "0X", 2) == 0)
284+
{
285+
p = optarg + 2;
286+
l -= 2;
287+
}
288+
else
289+
{
290+
p = optarg;
291+
}
245292
}
246293
else
247294
{
248-
reg += (optarg[2] - 'A' + 10) * 16;
249-
}
250-
if ((optarg[3] <= '9') && (optarg[3] >= '0'))
251-
{
252-
reg += (optarg[3] - '0');
295+
p = optarg;
253296
}
254-
else
297+
298+
/* init 0 */
299+
hex_data = 0;
300+
301+
/* loop */
302+
for (i = 0; i < l; i++)
255303
{
256-
reg += (optarg[3] - 'A' + 10);
304+
if ((p[i] <= '9') && (p[i] >= '0'))
305+
{
306+
hex_data += (p[i] - '0') * (uint32_t)pow(16, l - i - 1);
307+
}
308+
else if ((p[i] <= 'F') && (p[i] >= 'A'))
309+
{
310+
hex_data += ((p[i] - 'A') + 10) * (uint32_t)pow(16, l - i - 1);
311+
}
312+
else if ((p[i] <= 'f') && (p[i] >= 'a'))
313+
{
314+
hex_data += ((p[i] - 'a') + 10) * (uint32_t)pow(16, l - i - 1);
315+
}
316+
else
317+
{
318+
return 5;
319+
}
257320
}
321+
322+
/* set the data */
323+
reg = hex_data & 0xFFFF;
258324

259325
break;
260326
}

0 commit comments

Comments
 (0)