1 2 #include <stdint.h> 3 #include <stdio.h> 4 #include <stdlib.h> 5 6 #include "raspi_get_model.h" 7 8 /** 9 * Raspberry Pi model detection based on, 10 * https://elinux.org/RPi_HardwareHistory 11 **/ raspi_get_model()12int raspi_get_model() 13 { 14 FILE *f = fopen( "/proc/cpuinfo", "rb" ); 15 if( f == NULL ) 16 { 17 perror( "can't open cpuinfo!" ); 18 return MODEL_UNKNOWN; 19 } 20 21 int ret = 0; 22 uint32_t revision = 0; 23 uint32_t model = MODEL_UNKNOWN; 24 char line[100] = { 0 }; 25 char *ptr = NULL; 26 for(; ret < 1;) 27 { 28 ptr = fgets( line, 100, f ); 29 if( ptr == NULL ) 30 break; 31 ret = sscanf( line, "Revision : %x\n", &revision ); 32 } 33 34 fclose( f ); 35 36 switch( revision ) 37 { 38 case 0x9000c1: 39 model = MODEL_ZERO_W; 40 break; 41 case 0xa02082: 42 case 0xa22082: 43 case 0xa32082: 44 model = MODEL_3B; 45 break; 46 case 0xa020d3: 47 model = MODEL_3BPLUS; 48 break; 49 case 0x9020e0: 50 model = MODEL_3APLUS; 51 break; 52 default: 53 break; 54 } 55 56 return model; 57 } 58 59 60