Problem with using Stylus in KDE

I am using rog flow 13 which has a touchable screen that supports MPP. It is running KDE plasma on Wayland. I was trying to use a surface pen with it but the pen didn’t work. The pen was connected via blue tooth, but kde didn’t recognize it as a stylus device. I was able to see the device using sudo evtest /dev/input/event13as it gives the output fine with absolute x and y coordinates. The mouse pointer also appear and disappear when I move the sylus up and down. I also tried to use a separated drawing tablet which worked fine with the computer. I would appreciate any help on how to solve it or suggest what happend.

sudo evtest /dev/input/event13 gives the output below:

Input device ID: bus 0x18 vendor 0x4f3 product 0x40fd version 0x100
Input device name: "ELAN9008:00 04F3:40FD Stylus"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 320 (BTN_TOOL_PEN)
    Event code 321 (BTN_TOOL_RUBBER)
    Event code 330 (BTN_TOUCH)
    Event code 331 (BTN_STYLUS)
  Event type 3 (EV_ABS)
    Event code 0 (ABS_X)
      Value  14810
      Min        0
      Max    18176
      Resolution      63
    Event code 1 (ABS_Y)
      Value   8054
      Min        0
      Max    11008
      Resolution      61
    Event code 24 (ABS_PRESSURE)
      Value      0
      Min        0
      Max     4096
    Event code 26 (ABS_TILT_X)
      Value      0
      Min    -9000
      Max     9000
      Resolution    5730
    Event code 27 (ABS_TILT_Y)
      Value      0
      Min    -9000
      Max     9000
      Resolution    5730
    Event code 40 (ABS_MISC)
      Value      0
      Min        0
      Max    36000
  Event type 4 (EV_MSC)
    Event code 4 (MSC_SCAN)
Properties:
  Property type 1 (INPUT_PROP_DIRECT)

sudo libinput list-devices gives two relavant entries as below:

Kernel:                  /dev/input/event13 
Id:                      i2c:04f3:40fd 
Group:                   6 
Seat:                    seat0, default 
Size:                    289x180mm 
Capabilities:            tablet  
Tap-to-click:            n/a 
Tap-and-drag:            n/a 
Tap button map:          n/a 
Tap drag lock:           n/a 
Left-handed:             disabled 
Nat.scrolling:           n/a 
Middle emulation:        n/a 
Calibration:             identity matrix 
Scroll methods:          none 
Scroll button:           n/a 
Scroll button lock:      n/a 
Click methods:           none 
Clickfinger button map:  n/a 
Disable-w-typing:        n/a 
Disable-w-trackpointing: n/a 
Accel profiles:          none 
Rotation:                n/a 
Area rectangle:          n/a

Device:                  Surface Pen Keyboard 
Kernel:                  /dev/input/event26 
Id:                      bluetooth:045e:0921 
Group:                   9 
Seat:                    seat0, default 
Capabilities:            keyboard  
Tap-to-click:            n/a 
Tap-and-drag:            n/a 
Tap button map:          n/a 
Tap drag lock:           n/a 
Left-handed:             n/a 
Nat.scrolling:           n/a 
Middle emulation:        n/a 
Calibration:             n/a 
Scroll methods:          none 
Scroll button:           n/a 
Scroll button lock:      n/a 
Click methods:           none 
Clickfinger button map:  n/a 
Disable-w-typing:        n/a 
Disable-w-trackpointing: n/a 
Accel profiles:          n/a 
Rotation:                0.0 
Area rectangle:          n/a

I found where was the issue. There were two issues. Firstly, my pen was not included in libwacom, so I have to manually add it. Apart from that, the calibration matrix was set to a very weird and small matrix with values like -1.xxxxxe-07. I changed the matrix back to an identity matrix and all worked out.