Skip to content

Instantly share code, notes, and snippets.

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:
#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)
{
# Check gpio usage
mount -t debugfs debugfs /sys/kernel/debug
cat /sys/kernel/debug/gpio
...
//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);
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) {
@sepfy
sepfy / read.sh
Created September 20, 2020 04:03
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
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;
}
#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)
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);
@sepfy
sepfy / fops.c
Last active October 4, 2020 05:03
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;
}