tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/sdcard/cid.go (about)

     1  package sdcard
     2  
     3  import "fmt"
     4  
     5  type CID struct {
     6  	//// byte 0
     7  	ManufacturerID byte
     8  	//uint8_t mid;  // Manufacturer ID
     9  	//// byte 1-2
    10  	OEMApplicationID uint16
    11  	//char oid[2];  // OEM/Application ID
    12  	//// byte 3-7
    13  	ProductName string
    14  	//char pnm[5];  // Product name
    15  	//// byte 8
    16  	ProductVersion string
    17  	//unsigned prv_m : 4;  // Product revision n.m
    18  	//unsigned prv_n : 4;
    19  	//// byte 9-12
    20  	ProductSerialNumber uint32
    21  	//uint32_t psn;  // Product serial number
    22  	//// byte 13
    23  	ManufacturingYear  byte
    24  	ManufacturingMonth byte
    25  	//unsigned mdt_year_high : 4;  // Manufacturing date
    26  	//unsigned reserved : 4;
    27  	//// byte 14
    28  	//unsigned mdt_month : 4;
    29  	//unsigned mdt_year_low : 4;
    30  	//// byte 15
    31  	Always1 byte
    32  	//unsigned always1 : 1;
    33  	CRC byte
    34  	//unsigned crc : 7;
    35  }
    36  
    37  func NewCID(buf []byte) *CID {
    38  	return &CID{
    39  		ManufacturerID:      buf[0],
    40  		OEMApplicationID:    (uint16(buf[0]) << 8) | uint16(buf[1]),
    41  		ProductName:         string(buf[3:8]),
    42  		ProductVersion:      fmt.Sprintf("%d.%d", (buf[8]&0xF0)>>4, buf[8]&0x0F),
    43  		ProductSerialNumber: (uint32(buf[9]) << 24) | (uint32(buf[10]) << 16) | (uint32(buf[11]) << 8) | uint32(buf[12]),
    44  		ManufacturingYear:   (buf[13] & 0xF0) | (buf[14] & 0x0F),
    45  		ManufacturingMonth:  (buf[14] & 0xF0) >> 4,
    46  		Always1:             (buf[15] & 0x80) >> 7,
    47  		CRC:                 buf[15] & 0x7F,
    48  	}
    49  }