This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PWD := $(shell pwd) | |
KVERSION := $(shell uname -r) | |
KERNEL_DIR = /usr/src/linux-headers-$(KVERSION)/ | |
MODULE_NAME = mydev | |
obj-m := $(MODULE_NAME).o | |
all: | |
make -C $(KERNEL_DIR) M=$(PWD) modules | |
clean: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/module.h> | |
#include <linux/device.h> | |
#include <linux/err.h> | |
int value = 0; | |
static ssize_t attr_store(struct device *dev, | |
struct device_attribute *attr, | |
const char *buf, size_t count) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check gpio usage | |
mount -t debugfs debugfs /sys/kernel/debug | |
cat /sys/kernel/debug/gpio |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
//char* reportedProperties = serializeToJson(&car); | |
char reportedProperties[512]; | |
sprintf(reportedProperties, "{\"temperature\": 27.6, \"humidity\": 67.3}"); | |
if (reportedProperties != NULL) | |
{ | |
(void)IoTHubDeviceClient_LL_SendReportedState(iotHubClientHandle, (const unsigned char*)reportedProperties, strlen(reportedProperties), reportedStateCallback, NULL); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int val = 0; | |
int temp, humi; | |
u8 bytes[6] = {0}; | |
const u8 cmd[6] = {0}; | |
u32 s; | |
printk("[%s][%d]\n", __func__, __LINE__); | |
s = i2c_smbus_write_i2c_block_data(i2c_client, 0x24, 1, cmd); | |
if(s < 0) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "scale=2; -45 + 175*$(cat /sys/class/sensor/sht31/temperature)/65535" | bc | |
echo "scale=2; 100*$(cat /sys/class/sensor/sht31/humidity)/65535" | bc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static ssize_t attr_store(struct device *dev, | |
struct device_attribute *attr, | |
const char *buf, size_t count) | |
{ | |
printk("[%s][%d]\n", __func__, __LINE__); | |
buzzer_trigger = simple_strtoul(buf, NULL, 10); | |
gpio_set_value(BUZZER, buzzer_trigger); | |
return count; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define BUZZER 23 | |
#define BUTTON 21 | |
static short int button_irq = 0; | |
static unsigned long flags = 0; | |
int buzzer_trigger = 0; | |
u32 trigger_jiffies; | |
static irqreturn_t button_isr(int irq, void *data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static struct miscdevice my_miscdev = { | |
.minor = 11, | |
.name = "misc_dev", | |
.fops = &mydev_fops, | |
}; | |
static int __init init_modules(void) | |
{ | |
int ret; | |
ret = misc_register(&my_miscdev); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static ssize_t | |
mydev_read(struct file *filp, char __user *buf, size_t count, loff_t *pos) | |
{ | |
char tmp[] = "Kernel says hello"; | |
printk("[%s][%d]\n", __func__, __LINE__); | |
copy_to_user(buf, tmp, sizeof(tmp)); | |
*pos = 0; | |
return 0; | |
} |