mirror of
https://github.com/lupyuen/pinephone-nuttx.git
synced 2025-01-13 05:08:32 +08:00
Add CRC
This commit is contained in:
parent
a53572dee3
commit
13cb94c74b
1 changed files with 14 additions and 6 deletions
20
display.zig
20
display.zig
|
@ -35,6 +35,7 @@ const c = @cImport({
|
||||||
@cInclude("arch/types.h");
|
@cInclude("arch/types.h");
|
||||||
@cInclude("../../nuttx/include/limits.h");
|
@cInclude("../../nuttx/include/limits.h");
|
||||||
@cInclude("nuttx/config.h");
|
@cInclude("nuttx/config.h");
|
||||||
|
@cInclude("nuttx/crc16.h");
|
||||||
@cInclude("inttypes.h");
|
@cInclude("inttypes.h");
|
||||||
@cInclude("unistd.h");
|
@cInclude("unistd.h");
|
||||||
@cInclude("stdlib.h");
|
@cInclude("stdlib.h");
|
||||||
|
@ -132,10 +133,8 @@ fn composeLongPacket(
|
||||||
std.mem.copy(u8, pkt[header.len..], payload); // `len` bytes
|
std.mem.copy(u8, pkt[header.len..], payload); // `len` bytes
|
||||||
// Packet Footer comes later, after we have computed CRC...
|
// Packet Footer comes later, after we have computed CRC...
|
||||||
|
|
||||||
// TODO: Checksum (CS) (2 bytes):
|
// Checksum (CS) (2 bytes):
|
||||||
// - 16-bit Cyclic Redundancy Check (CRC)
|
// - 16-bit Cyclic Redundancy Check (CRC)
|
||||||
// See "12.3.6.13: Packet Footer", Page 210 of BL808 Reference Manual:
|
|
||||||
// https://github.com/sipeed/sipeed2022_autumn_competition/blob/main/assets/BL808_RM_en.pdf)
|
|
||||||
const cs: u16 = computeCrc(pkt[0..(pktlen - 2)]);
|
const cs: u16 = computeCrc(pkt[0..(pktlen - 2)]);
|
||||||
const csl: u8 = @intCast(u8, cs & 0xff);
|
const csl: u8 = @intCast(u8, cs & 0xff);
|
||||||
const csh: u8 = @intCast(u8, cs >> 8);
|
const csh: u8 = @intCast(u8, cs >> 8);
|
||||||
|
@ -194,13 +193,19 @@ fn computeEcc(
|
||||||
| (@intCast(u8, ecc[7]) << 7);
|
| (@intCast(u8, ecc[7]) << 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Compute 16-bit Cyclic Redundancy Check (CRC).
|
||||||
|
/// See "12.3.6.13: Packet Footer", Page 210 of BL808 Reference Manual:
|
||||||
|
/// https://github.com/sipeed/sipeed2022_autumn_competition/blob/main/assets/BL808_RM_en.pdf)
|
||||||
fn computeCrc(
|
fn computeCrc(
|
||||||
data: []u8
|
data: []u8
|
||||||
) u8 {
|
) u16 {
|
||||||
_ = data;
|
// Use NuttX CRC16
|
||||||
return 0;
|
return c.crc16(data.ptr, data.len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// MIPI DSI Types
|
||||||
|
|
||||||
/// MIPI DSI Device
|
/// MIPI DSI Device
|
||||||
pub const mipi_dsi_device = extern struct {
|
pub const mipi_dsi_device = extern struct {
|
||||||
/// Number of Data Lanes
|
/// Number of Data Lanes
|
||||||
|
@ -251,6 +256,9 @@ pub const mipi_dsi_timings = extern struct {
|
||||||
vsync: u32,
|
vsync: u32,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Test Functions
|
||||||
|
|
||||||
/// Main Function for Null App
|
/// Main Function for Null App
|
||||||
pub export fn null_main(_argc: c_int, _argv: [*]const [*]const u8) c_int {
|
pub export fn null_main(_argc: c_int, _argv: [*]const [*]const u8) c_int {
|
||||||
_ = _argc;
|
_ = _argc;
|
||||||
|
|
Loading…
Reference in a new issue